作者JustinHere (良葛格)
看板java
标题Re: [问题] new在括号中的用法
时间Thu Jun 19 07:07:22 2014
※ 引述《dharma (达)》之铭言:
: Java书前面章节出现的new
: 几乎都是下面这行的用法:
: Car car = new Car();
: 但到了Collections章节
: 却开始大量出现下面这种new出现在括号中的用法:
: ArrayList<Integer> num = new ArrayList<>()
: …
: num.add(new Integer(i));
: 这种new用法是在哪个章节有说明啊
: 怎麽没印象
: thank
你也可以写成这样…
ArrayList<Integer> num = new ArrayList<>();
...
Integer boxedI = new Integer(i);
num.add(boxedI);
只不过变数boxedI只用在这边的话,不如就直接建完Integer实例就直接传给add…
--
良葛格学习笔记
http://openhome.cc
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 180.204.227.229
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/java/M.1403132846.A.6A7.html
1F:推 dharma:感谢 06/19 08:55
2F:→ ah7675:是良葛格! 你的部落格惠我良多啊 06/19 22:05
3F:推 BlackZap:神人... 06/20 01:03
4F:→ NewSpec:良葛格在某事件之後真是常发言阿...不过..嘉惠新手, 赞! 06/20 02:04
5F:→ JustinHere:2007年还是新手吧!那时觉得不适合来了..XD 06/20 07:17
※ 编辑: JustinHere (117.19.247.142), 06/20/2014 07:18:22
6F:推 kor525:神人~~~~~~ 06/26 11:52