Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AutoBoxing in Collections

 
Jart Bo
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Hi Guys,

I just wanted to confirm. This compiles so in any type of legacy collection, primitives are going to be autoboxed right? Thanks!

[ May 13, 2008: Message edited by: Jart Bo ]
[ May 13, 2008: Message edited by: Jart Bo ]
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bo,

I think you can yourself compile this code and see anyway i think it will work.I don't find any problem with that.
 
sridhar row
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jart Bo,

It will work as long as it is Java 5. Prior to Java 5 there was no Autoboxing feature so probably give a compiler error.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jart Bo:
I just wanted to confirm. This compiles so in any type of legacy collection, primitives are going to be autoboxed right?

What is normally meant by a "legacy collection" is one of the old collection classes (such as Vector or Hashtable), from Java 1.1, before the collections framework was added.

But I guess here you mean a collection without using generics.

Yes, primitive values will be autoboxed, also when using a collection without generics.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic