Originally posted by Campbell Ritchie:
Agree with Henry Wong. The sooner you get used to creating objects with "new" the better.
Originally posted by Henry Wong:
Why is learning to instantiate an object via the new operator a bad idea? Or are you saying that using the new operator versus valueOf() for the wrapper types a bad idea in general?
Henry
"I'm not back." - Bill Harding, Twister
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Originally posted by Jim Yingst:
[Dick]: "Is new within the valueOf() method?"
Yes and no. There's a new in valueOf(), which executes in some situations. Not, as it happens, in this particular situation. But there is additional code inside the Integer class, not in the valueOf() method, which leads to the creation of a preexisting cache of Integer objects available instantly on demand. These objects are also created with new. That's what happened here - when the Integer class was first used, it was loaded and initialized, and 256 Integer objects were created using "new", including one for 123.
Thanks to all who answered...
especially for the intereseting bit about the "string pool" mentioned by Henry and Jim. Presumeably this is the one you can use:
Originally posted by Henry Wong:
I don't believe that I mentioned anything about the string pool. The integer cache is something completely different -- and currently supports only a fixed range.
Henry
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |