我有这个问题,有点理论化,但我想理解它。
为什么如果我将 null 参数传递给构造函数,我会得到一个NullPointerException
?
这是我的例子
new AttendeeDetail("Gus Goose","1151","15-01-2012",(Integer) null,null)
这是班级:
public class AttendeeDetail {
private String ticketholder_name;
private String user_id;
private String date_of_birth;
private int tickets_purchased;
private ArrayList<Ticket> tickets;
public AttendeeDetail(String ticketholder_name, String user_id,
String date_of_birth, int tickets_purchased, ArrayList<Ticket> tickets)
{
this.ticketholder_name=ticketholder_name;
this.user_id=user_id;
this.date_of_birth=date_of_birth;
this.tickets_purchased=tickets_purchased;
this.tickets=tickets;
}
}
an int
不可能null
。
如果确实需要传递空值,请使用Integer
type
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)