Why is there no Constant feature in Java?

后端 未结 8 1887
青春惊慌失措
青春惊慌失措 2020-11-28 02:20

I was trying to identify the reason behind constants in Java I have learned that Java allows us to declare constants by using final keyword.

My question

8条回答
  •  广开言路
    2020-11-28 02:54

    You can use static final to create something that works similar to Const, I have used this in the past.

    protected static final int cOTHER = 0;
    protected static final int cRPM = 1;
    protected static final int cSPEED = 2;
    protected static final int cTPS = 3;
    protected int DataItemEnum = 0;
    
    public static final int INVALID_PIN = -1;
    public static final int LED_PIN = 0;
    

提交回复
热议问题