Этот момент, лично мне, кажется, мягко говоря, спорным.
As of release 1.5, there is a third approach to implementing singletons. Simply
make an enum type with one element:
// Enum singleton - the preferred approach
public enum Elvis {
INSTANCE;
public void leaveTheBuilding() { ... }
}
This approach is functionally equivalent to the public
(
Read more... )
Comments 7
Reply
serialization or reflection attacks")
Reply
Reply
(The comment has been removed)
Аналог методов foo() и bar().
Reply
назначение енумов, с моей точки зрения, ну никак не держать синглтоны, тем более что нормальной lazy initialization оно все равно не умеет
Reply
Reply
Your approach from what i see is not safe in multi threaded environment, plus you are doing eager initialization.
or am i missing something?
Single-element enum type is final, and is safe against reflection attacks.
Reply
Leave a comment