首页 > 学院 > 开发设计 > 正文

作了个小测试equals 和==

2019-11-18 11:19:32
字体:
来源:转载
供稿:网友

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



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表