java Singleton - prevent multiple creation through reflection

前端 未结 6 896
无人及你
无人及你 2021-01-30 22:52

I have a singleton like this.

public class BookingFactory {

    private final static BookingFactory instance;

    static {
        instance = new BookingFactor         


        
6条回答
  •  再見小時候
    2021-01-30 23:51

    If your singleton does not actually store state, then your best option is to not use a singleton. Instead, implement the factory as a static state-free method.

提交回复
热议问题