I want to use something like Setting.RES_WIDTH in my code without the need for a getter function (i.e.: custom getter, enum's .name(), .toString() or .valueOf()).

Someone suggested using a final class, so I wrote this:

public final class Setting {

    public final static String RES_WIDTH        = "resolution_width";
    public final static String RES_HEIGHT       = "resolution_height";
    public final static String FULLSCREEN       = "fullscreen_enabled";
    public final static String VSYNC            = "vsync_enabled";

    //Prevent someone from creating an instance of this class
    private Setting() {}

This code works, but I am wondering if there are any kind of issues (performance, GC, etc) that might arise from using this.

  • \$\begingroup\$ Seems to me like you worry to much. Have you heard the saying about premature optimization? \$\endgroup\$ Jan 31, 2016 at 0:25
  • \$\begingroup\$ I haven't, I'll look it up. But yes, that's quite possible, even with websites I worry a lot about optimizing my code the best way possible, even if it probably only makes 1 cpu-cycle of difference haha \$\endgroup\$
    – xorinzor
    Jan 31, 2016 at 0:27

1 Answer 1


There won't be any GC overhead since there won't be any instantiated instances to collect.

I think there's a small overhead by accessing a class' static field rather than an in-scope variable ; however, I would consider it largely worth the improved readability/maintainability.

I guess you could also argue you'll use up a little bit more of your permGen / Meta space, but I've never heard it be a consequent problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.