【发布时间】:2014-11-06 06:17:44
【问题描述】:
Class Wrapper{
psvm(){
Integer i=new Integer(5);
Float f=new Float(5);
}
}
如果 (i==f && i.equals(f))// 第一个表达式的计算结果为 ????第二个表达式的计算结果为???
System.out.println("i == f returns " + (i == f) + " and equals returns " + i.equals(f));
【问题讨论】:
-
你到底在问什么?
-
你为什么不试试呢?
-
您有一份打印声明。为什么不使用它?
-
我想知道 == 和 equals 在这种情况下是如何工作的?
-
@SagarByali 在 Java1.7 中代码无法编译:
Incompatible operand types Integer and Float。所以这个语句不能被评估。