[Java daily question] 20170208, java20170208
20170207 for problem resolution, click "Java daily question" 20170208 "below today's question to view the problem (The problem is resolved at the beginning of the public account, public ID: weknow619)
package Feb2017; public class Ques0208 { } class Person{ private String id; private String name; public Person(String id, String name) { super(); this.id = id; this.name = name; } @Override public boolean equals(Object o) { if (o != null && o instanceof Person) { Person person = (Person)o; return (id.equals(person.id) && name.equals(person.name)); } return false; } }
Today's question:
In the if condition judgment of the equals method in the Person class, if the object is not checked for being null (remove o! = Null, write only o instanceof Person). If the input object is null, will a null pointer exception be reported? (Click "[Java daily question] 20170208" below to view issue resolution 20170207)
Questions originally published on the public account and short book: [Java daily question] 20170208, [Java daily question] 20170208 (you can also scan the Avatar QR code to view)
The weknow team has activated the authentication and has answered questions. If you have any questions, you can also consult. Click the answer to find me!