作了个小测试equals 和==

王朝other·作者佚名  2008-05-31
宽屏版  字体: |||超大  

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!

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有