Java constant examples (Create a java file having only constants)

前端 未结 5 664
别那么骄傲
别那么骄傲 2021-01-31 03:14

What is the best practice to declare a java file having only constant?

public interface DeclareConstants
{
    String constant = \"Test\";
}

OR

5条回答
  •  醉梦人生
    2021-01-31 03:34

    - Create a Class with public static final fields.

    - And then you can access these fields from any class using the Class_Name.Field_Name.

    - You can declare the class as final, so that the class can't be extended(Inherited) and modify....

提交回复
热议问题