假如自己创建自己的类 情况又不一样

== 和金沙网址,!=

//: object/test.javapackage object;import java.util.*;public class Test{    public static void main(String[] args)    {        Integer n1 = new Integer(47);        Integer n2 = new Integer(47);        System.out.println(n1 == n2);//output false        System.out.println;//output true    }}
//比较的是对象的引用

equals:equals 不适用于基本类型,基本项目用== !=

//: object/test.javapackage object;import java.util.*;public class Test{    public static void main(String[] args)    {        int n1 = 100;        int n2 = 100;        System.out.println(n1==n2);//output false    }}

equals

//: object/test.javapackage object;import java.util.*;public class Test{    public static void main(String[] args)    {        Integer n1 = new Integer(47);        Integer n2 = new Integer(47);        System.out.println(n1.equals;//output true    }}

equals:即便自身创办和谐的类 景况又不相同

//: object/test.javapackage object;import java.util.*;class Value{    int i;}public class Test{    public static void main(String[] args)    {        Value n1 = new Value();        Value n2 = new Value();        n1.i = n2.i = 100;        System.out.println(n1.equals;//output false    }}

相关文章