服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

作了个小测试equals 和==

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

扫描关注微信公众号