zno2

Item 1: Consider static factory methods instead of constructors

实际应用:

package java.lang;

public final class Boolean implements java.io.Serializable, Comparable<Boolean> {

    public static final Boolean TRUE = new Boolean(true);

    public static final Boolean FALSE = new Boolean(false);

....

    private final boolean value;

....

    public Boolean(boolean value) {
        this.value = value;
    }
....

    public static Boolean valueOf(boolean b) {
        return (b ? TRUE : FALSE);
    }
....
}

 

 

 

 

构造器(Constructor)

https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8

方法签名(method signature)

https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

基本类型和引用类型(PrimitiveType and ReferenceType)

https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.1

== 和 equals(Object obj)

https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html

 

posted on 2023-06-06 13:19  zno2  阅读(13)  评论(0编辑  收藏  举报

导航