Immutable Law of Java #20: The new Keyword

Discussions

News: Immutable Law of Java #20: The new Keyword

  1. Immutable Law of Java #20: The new Keyword (3 messages)

    This won't be anything new for the veteran Java programmer, but for those learning the language, having a few hard and fast rules that you can always depend on makes learning the language easier. Point your junior Java developers at this little advice column. It'll make them better programmers, unless of course, it doesn't make them better programmers; that's a promise.

    An Immutable Law of Java: The new Keyword

  2. Why is this posted here?

  3. postings[ Go to top ]

    Should it not be?

  4. When we go about telling people when they should or shouldn't do things, it's good to be complete:

    [b]When to use new String()[/b]: If you calling substr on a potentially large string, and you do not want to keep the remaining parts of the large string, you should use new String() aroung the substr() call.  If you do not, the entire backing array for the original (large) array will be retained in memory as long as the substr portion is not GC'd.