作了个小测试equals 和==

类别:Java 点击:0 评论:0 推荐:
public class Sample{ long length; public Sample(long l){length = l;} public static void main(String arg[]){ Sample s1,s2,s3; s1=new Sample(21L); s2=new Sample(21L); s3=s2; String st1="hello"; String st2="hello"; String st3= new String("hello"); int i=3; Integer j=new Integer(3); float f =3.000f; Float fl =new Float(3.0f); Float f2 =new Float(3.0f); long m=21L; System.out.println(fl.equals(i));//false System.out.println(j.equals(f));//false System.out.println(s1.equals(s2));//true??false!!!!! System.out.println(fl.equals(f2));//true System.out.println(s2==s3);//true System.out.println(s1==s3);//false System.out.println(st1==st2);//true System.out.println(st3==st2);//false System.out.println(fl.equals(3));//false System.out.println(fl==f);//true if(i==f) System.out.println("equal1");//do if(i==fl) System.out.println("equal2");//do if(f2==fl) System.out.println("equal3");//undo if(i==f2) System.out.println("equal4");//do //if(s1==fl)System.out.println("equal3");cannot be compiled! } }

本文地址:http://com.8s8s.com/it/it13318.htm