The question:
Fix the following code so the the map.get() call retrieves the expected value. Do not change the main method.
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" ) ) );
}
}
Now I know I can get the answer by changing the main method like so:
Student s = new Student("john")
System.out.println( map.get( s) );
but how can I achieve this without changing the main method?