在java中是没有指针的 实际上 引用reference 就是指针pointer
但是他是受控的,安全的,比如会检查空引用,没有指针运算*() 不能访问没有引用到的内存 自动回收垃圾
JAVA中 JNI(调用其他语言代码来交互或者调用操作系统那些函数) 混编
== 这个符号,简单的说,基本类型是值相等,引用类型是引用相等
数值类型,转换后比较
浮点数最好不要直接用== 因为浮点数是有误差的,一般判断它的差
boolean和int无法比较
Integer i=new Integer(10);
Integer j=new Integer(10);
System.out.println(i==j);//false,因为对象是两个
Integer m=10;
Integer n=10;
System.out.println(m==n);//true,因为对象有缓存
Integer p=200;
Integer q=200;
System.out.print(p==q);//false 因为对象是两个
注意缓存: JDK文档里有
枚举类型,内部进行了惟一实例化,所以可以直接判断
引用对象,是直接看两个引用是否一样 如果要判断内容是否一样,则要重写equals方法
如果重写equals方法,则最好重写hashCode()方法
String对象
判断相等,一定不要用==,要用equals
但是字符串常量(String literal)及字符串常量会进行内部化(interned)相同的字符串常量是==的
String helo="Hello",ol="ol";
System.out.println(hello="Hello");//true
System.out.println(Other.hello==hello);//true
System.out.println(hello==("Hel"+"lo"));//true
System.out.println(hello==("Hel"+lo));//false
这个是因为"Hel"是个常量 lo是个变量 变量加常量 不会加在一起
System.out.println(hello==new String("Hello"));//false
后面是New新创建的对象,和原来哪个常量没有关系 所以是false
System.out.println(hello==("Hel"+lo).intern());//true
intern()是求得它内部化里面的一个字符串,所以这两个相等