如果你定义的类仅仅是包含了一些静态的方法和静态的字段,这些类一般是一些工具类,这些一般是设计为不能被实例化的。
1. Attempting to enforce noninstantiability by making a class abstract does not work.
2. a class can be made noninstantiable by including a private constructor
// Noninstantiable utility class public class UtilityClass { // Suppress default constructor for noninstantiability private UtilityClass() { throw new AssertionError(); } ... // Remainder omitted }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/15970.html