我有这个类值“零”默认情况下,字符串
public class Model {
private String a;
private String b;
public synchronized String getA() {
return a;
}
public synchronized void setA(String a) {
this.a = a;
}
public synchronized String getB() {
return b;
}
public synchronized void setB(String b) {
this.b = b;
}
}
我想方设法把a
的价值,我也知道,通过default这个变量初始化为null
。但是,如果我调用getA()
方法,那么这个变量是否有可能存在字符串"null"
(不是null
,而是String
)?所以a.equals("null") == true
。
public static void main(String[] args) throws ParseException {
Model m = new Model();
String test = m.getA();
m.getA().equals("null");//No Exception occurs
}
而事实上,我EVAL字符串是一个Android应用程序的一部分代码:
mAirline = (Airline) extras.getSerializable("airline");
@SuppressWarnings("unused")
String test = mAirline.getPhone(); //(1)
String test2 = mAirline.getHref(); //(2)
如果我在检查mAirline(1)mAirline有它在空字段,但在(2)有一些他们“空”而我的方法得到是
public synchronized String getPhone() {
return phone;
}
你不明白你在问什么,你发布的代码片段甚至没有编译,因为'a'没有定义。如果你没有明确设置'm.a'的值,它本身不会改变。 –
对不起,希望现在更清楚。 – Dayerman
除了你要重写m.getA()。equals(“null”)为“null”.equals(m.getA())的答案。 –