[Logo]
Forums Register Login
legacy way to do collections
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
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
 
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?
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!
 
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?
Yes, check by compiling!
thanks sir for quick reply and clearing doubts.
You are Welcome!
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Oct 21, 2017 03:05:40.