ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  10 Reasons We Need Java 3.0
Subject:   get rid of public constructors
Date:   2002-08-06 16:28:49
From:   friendless
I would like to see constructors all be private, so that you have to invoke a static factory method to get a new instance of anything. The problem with public constructors is that as soon as you call "new", memory is allocated, even if an identical object already exists. For immutable classes, such as Integer and String, arbitrary amounts of memory can be wasted by useless creation of duplicate instances. By making constructors private, use of memory by a class is controlled by the implementors of that class, who understand it best in any case.

1 to 2 of 2
  1. get rid of public constructors
    2004-01-07 21:00:24  anonymous2 [View]

  2. get rid of public constructors
    2002-08-07 01:03:15  jdavi [View]

1 to 2 of 2