This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes legacy way to do collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "legacy way to do collections" Watch "legacy way to do collections" New topic
Author

legacy way to do collections

Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

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: 432

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: 432

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: 432

thanks sir for quick reply and clearing doubts.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

You are Welcome!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: legacy way to do collections