Use of private constructor to prevent instantiation of class?

Posted by cringe on Stack Overflow See other posts from Stack Overflow or by cringe
Published on 2010-04-30T09:10:08Z Indexed on 2010/04/30 9:17 UTC
Read the original article Hit count: 209

Filed under:
|

Hi guys!

Right now I'm thinking about adding a private constructor to a class that only holds some String constants.

public class MyStrings {
  // I want to add this:
  private MyString() {}

  public static final String ONE = "something";
  public static final String TWO = "another";
  ...
}

Is there any performance or memory overhead if I add a private constructor to this class to prevent someone to instantiate it?

Do you think it's necessary at all or that private constructors for this purpose are a waste of time and code clutter?

© Stack Overflow or respective owner

Related posts about java

Related posts about Performance