//如我在.NET中声明一些属性如//年龄 可为空
public int? Age {get;set;}
//出生 可为空
public DateTime? Birthday {get;set;}
//是否选中 可为空
public bool? IsChecked {get;set;}//然后我可以对数据进行赋值如
info.Age=12;
info.Age=null;
info.Birthday = null
info.Birthday = DateTime.Now;
info.IsChecked = null
info.IsChecked = true;
那以上代码在Java中如何来实现谢谢
public int? Age {get;set;}
//出生 可为空
public DateTime? Birthday {get;set;}
//是否选中 可为空
public bool? IsChecked {get;set;}//然后我可以对数据进行赋值如
info.Age=12;
info.Age=null;
info.Birthday = null
info.Birthday = DateTime.Now;
info.IsChecked = null
info.IsChecked = true;
那以上代码在Java中如何来实现谢谢
---------------
??
这样的话,如果我的值有可能是null的话要怎么办?
Integer Date Boolean
private Date birthday;
private boolean IsChecked;他们都有默认的值
int 0 Date null boolean falsepiblic int getAge(){
return this.age;
}
private void setAge(int age){
this.age = age
}
我是想三个数据默认值都为null
而不是0,null, false
谢谢
int? 相当于,可为null,的int
bool? 相当于,可为null, 的bool如果要用String 来代替int? bool?的话,那每一次不是都得进行很要命的转换?
例如:
int 对应 Integer
double 对应 Double
boolean 对应 BooleanDateTime对应的是java.util.Date类,可以为null