| Author |
legacy way to do collections
|
Arjun Srivastava
Ranch Hand
Joined: Jun 23, 2010
Posts: 431
|
|
A non-generic collection can hold anything i.e. not a primitive.
please elaborate this statement and give me an example of adding a primitive type here.
above code compiles fine with 1.6 compiler
|
SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
|
 |
Sudhakar Sharma
Ranch Hand
Joined: Apr 04, 2009
Posts: 71
|
|
Hi Arjun,
I think line 4 will not compile in pre-java 5.0 compiler,
In java 5.0 primitives are auto-boxed to their wrapper type, hence ok with that.
"A non-generic collection can hold anything i.e. not a primitive." is very implicit because collection generic or non-generic cannot hold primitives.
please confirm
thank you
|
 |
Arjun Srivastava
Ranch Hand
Joined: Jun 23, 2010
Posts: 431
|
|
Sudhakar Sharma wrote:
line 4 will not compile in pre-java 5.0 compiler
that means adding primitive type to a non generic collection is possible with 1.5 and 1.6?
are you sure?
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
Since, auto-boxing available from 1.5, the primitives can be auto boxed into wrapper objects and can be added into collections. That's why you can add primitives in the above example!
And, normally, they are speaking about non-generics, because, in generics version, you can defined them, for example
So, they normally speak about, non-generic versions. Sudhakar Sharma is correct!
Arun, because of auto boxing, you able to add primitives, only objects can be added to collections!
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Arjun Srivastava
Ranch Hand
Joined: Jun 23, 2010
Posts: 431
|
|
Abimaran Kugathasan wrote:Since, auto-boxing available from 1.5
that means if we are using pre java 5 compiler it will shows an error on line 4?
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
Yes, check by compiling!
|
 |
Arjun Srivastava
Ranch Hand
Joined: Jun 23, 2010
Posts: 431
|
|
|
thanks sir for quick reply and clearing doubts.
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
You are Welcome!
|
 |
 |
|
|
subject: legacy way to do collections
|
|
|