how to get a constant in java with class

后端 未结 6 1295
一个人的身影
一个人的身影 2021-02-13 14:51

basically I need to get a constant for a class however I have no instance of the object but only its class. In PHP I would do constant(XYZ); Is there a similar way

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-13 15:45

    Maybe I don't understand what you need, but did you try with final static attributes and static methods?

    Final means that it can't be changed once set, so you get a constant. Static means it's accessible even if there aren't any objects of the class.

提交回复
热议问题