I have a map which returns the expected mapping when using the same AuthToken it was keyed with. However, it returns null when using an equivalent AuthToken
authToken2. I cannot think of any reason for this behavior and its driving me crazy. Am I missing something obvious here?
//initialize stuff User user = new User("Test", "User", "https://faculty.cs.byu.edu/~jwilkerson/cs340/tweeter/images/donald_duck.png"); AuthToken authToken = new AuthToken("key"); HashMap<AuthToken, User> loggedInUsersByAuthToken = new HashMap<>(); loggedInUsersByAuthToken.put(authToken, user); AuthToken authToken2 = new AuthToken("key"); System.out.println("authToken equals authToken2? " + authToken.equals(authToken2)); System.out.println("value from authToken is null? " + (loggedInUsersByAuthToken.get(authToken) == null)); //unexpected behaivor System.out.println("value from authToken2 is null? " + (loggedInUsersByAuthToken.get(authToken2) == null));
authToken equals authToken2? true value from authToken is null? false value from authToken2 is null? true