class Employee
{
int id;
Employee(int id)
{
this.id = id;
}
public int getID()
{
return id;
}
public void displayID()
{
System.out.println("ID="+id);
}
}
public class Example
{
public static void main(String[] args)
{
Employee employee1 = new Employee(100);
Employee employee3 = null;
List<Employee> arrayListEx = new ArrayList<Employee>();
Set<Employee> setEx = new HashSet<Employee>();
arrayListEx.add(employee1);
arrayListEx.add(employee3);
setEx.add(employee1);
setEx.add(employee3);
}
}
Friends, As per my understanding Set should not allow null values to get added to it. Should the above code snippet throw compile time error for "setEx.add(employee3)" ? Please advice, Thanks in advance.