Skip to main content

Posts

Showing posts from November, 2008

Java is Disappointing Sometimes...

What's Java's number one problem?  If you said "efficiency," then you win!  Why do we still use C and C++?  If you said "efficiency," then you also win! And so... yesterday, we learned about templates and generics and so forth, and I was able to ask a question that's been bugging me for quite some time.  "When you declare an ArrayList<Integer>, are Integer Objects being stored internally, or are primitive ints being stored?" Prior to yesterday, I had given this quite a bit of thought, actually.  I'd say about a year ago, I determined that since the classes like Integer, Byte, Float were final, non-inheritable classes, that Java could actually optimize the language by artificially storing primitive ints, auto-unboxing and auto-boxing them, as appropriate.  But, as it turned out, I was wrong! Java does not do that.  Instead, when you store a bunch of "primitive ints" in an ArrayList<Integer>, what actually happens