import java.util.HashMap;
import java.util.Map;
public class StudentTest {
public static final class Student {
public Student( String name ) {
this.name = name;
}
private String name;
}
public static void main(final String[] args ) {
Map<Student, String> map = new HashMap<>();
map.put( new Student( "john"), "present" );
System.out.println( map.get( new Student( "john" ) ) );
}
I know how to make this work by changing the main function and initializing the object but is it possible to achieve the result without touching the main? I was asked this in an interview.
I have spent a lot of time googling but haven’t been able to get close to the answer. I’m not even sure what should be my search parameters anymore. Please help.