Java: null in constructor
•
Java
Excuse me, this question is a bit theoretical, but I want to understand it
Why do I pass null parameters to constructors? Do I get NullPointerException?
This is my example
new AttendeeDetail("Gus Goose","1151","15-01-2012",(Integer) null,null)
This is the class:
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;
}
}
Solution
Int cannot be null If you do need to pass a null value, use the integer type
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
