Java:构造函数中的NULL [英] Java: NULL in constructor
本文介绍了Java:构造函数中的NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问这个问题有点理论化,但我想理解它。
Please I have this question which is a bit theoretical, but I would like to understand it.
为什么我将null参数传递给构造函数? a NullPointerException
?
Why if I pass a null argument to a constructor do I get a 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;
}
}
推荐答案
int
不能 null
。
如果您确实需要传递空值,请使用整数
类型
这篇关于Java:构造函数中的NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文