WEB开发网
开发学院WEB开发Jsp 作了个小测试equals 和== 阅读

作了个小测试equals 和==

 2008-01-05 18:49:25 来源:WEB开发网   
核心提示: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

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! } }


Tags:测试 equals

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接