Java constants file

后端 未结 4 1741
名媛妹妹
名媛妹妹 2020-12-15 04:53

I\'m developing an Android application and I\'m very new on Java and Android.

I want to create some constants to use in some activities. Where can I define these con

4条回答
  •  别那么骄傲
    2020-12-15 05:27

    Normally, you'd use a Constants class, or define them in classes where they are used, a la:

    class Constants {
       public static final int NUM_TRIANGLES = 4;
       public static final String SOME_TEXT = "This is a constant";
    }
    

    Then you'd refer to them by:

    String inst = Constants.SOME_TEXT;
    

提交回复
热议问题