Skip to main content
1 of 2

java - using a final class for string constants

I want to use something like Setting.RES_WIDTH in my code without the need for a getter function (ie: 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.