Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

legacy way to do collections  RSS feed

 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 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
 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • 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
  • 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?
 
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 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
  • 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
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are Welcome!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!