File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

legacy way to do collections

 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, check by compiling!
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks sir for quick reply and clearing doubts.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are Welcome!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic