代码如下:
public class ClassTest {
String tem = " ";
Object temp = (this.temp == " "?" ":0);
Object ten = (this.tem == " "?" ":0);
Object tep = (this.temp == " "?" ":0);
public ClassTest(String temp){
this.temp = temp;
}
public static void main(String[] args){
ClassTest tr = new ClassTest(" ");
ClassTest td = new ClassTest("2");
System.out.println("---"+tr.ten+"---"+td.ten);
System.out.println("---"+tr.tep+"---"+td.tep);
}
}
运行结果:
--- ---
---0---0
------解决方案--------------------
------解决方案--------------------
无论new的参是什么
ten tep的值都是恒定为"" 和 0
------解决方案--------------------
哪里看不懂,一个类..有构造函数
------解决方案--------------------