- 论坛徽章:
- 0
|
Hi, All
Have a question about java.
- How do you usually define constants with a package?
- The only solution I can find is to define an "Constants Interface" like this:
- interface Constants
- {
- static final public int SUCCESS=1;
- static final public int FIAL=0;
- ... ...
- }
- Then, every class in the package using these constants has to implement this interface.
- An abstract final class defining these constants is an alternative, but then I have to site the class name when using the constants, like this:
- if( dosth()==Constant.SUCCESS)
- {... ...}
- I'm wondering if there is any other better solutions to define package constants? You know, Im some kind of new comer to java but am involved in a java project now.
复制代码 |
|