Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Создание через рефлексию фиксится конструкцией throw в конструкторе.
А организовать такое можно и случайно, настраивая какой-нибудь IoC-контейнер.
Создание через рефлексию фиксится конструкцией throw в конструкторе.
мне как-то ближе традиционные практики как в том же Objects — и final, и private конструктор, и исключение в нём.
An enum type has no instances other than those defined by its enum constants. It is a compile-time error to attempt to explicitly instantiate an enum type (§15.9.1).
In addition to the compile-time error, three further mechanisms ensure that no instances of an enum type exist beyond those defined by its enum constants:
The final clone method in Enum ensures that enum constants can never be cloned.
Reflective instantiation of enum types is prohibited.
Special treatment by the serialization mechanism ensures that duplicate instances are never created as a result of deserialization.
Нужна краткость — переходите на C#. Нам давным-давно статические классы завезли! (static class в C# = abstract final class в Java)
public enum Utils {
;
/**несколько методов, для экономии места не привожу*/
}
Class'ные Class'ы