Как определить класс констант в Java?JAVA

Программисты JAVA общаются здесь
Anonymous
Как определить класс констант в Java?

Сообщение Anonymous »


Предположим, вам нужно определить класс, который всего лишь хранит константы.

Код: Выделить всё

public static final String SOME_CONST = "SOME_VALUE";
What is the preferred way of doing this?
  • Interface
  • Abstract Class
  • Final Class
Which one should I use and why?


Clarifications to some answers:

Enums - I'm not going to use enums, I am not enumerating anything, just collecting some constants which are not related to each other in any way.

Interface - I'm not going to set any class as one that implements the interface. Just want to use the interface to call constants like so:

Код: Выделить всё

ISomeInterface.SOME_CONST
.


Источник: https://stackoverflow.com/questions/479 ... ts-in-java

Вернуться в «JAVA»