What is the preferred Throwable to use in a private utility class constructor?

前端 未结 8 1284
青春惊慌失措
青春惊慌失措 2020-12-14 01:07

Effective Java (Second Edition), Item 4, discusses using private constructors to enforce noninstantiability. Here\'s the code sample from the book:

public fi         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 01:33

    UnsupportedOperationException sounds like the best fit, though a checked exception would be even better, since it might warn someone erroneously instantiating the class at compile time.

提交回复
热议问题