Difference between java enum with no values and utility class with private constructor

后端 未结 4 1875
日久生厌
日久生厌 2020-12-29 19:30

A common thing to do to utility classes is to give them a private constructor:

public final class UtilClass {
    private UtilClass() {}

    ...
}
         


        
4条回答
  •  轮回少年
    2020-12-29 19:57

    Using enum for something that's not actually an enum is ugly and confusing. I'd say that's enough reason not to do it.

    The "utility class" pattern is perfectly legitimate. If your tools don't like it, that's a problem with the tools.

提交回复
热议问题