### Question:
UserId { @Override public int hashCode() { final int prime = BEST_PRIME; int result = 1; result = prime * result + registerDate; result = prime * result + ((userName == null) ? 0 : userName.hashCode()); return result; } UserId(String userName);  UserId(String userName, int registerDate);  UserId(String userName, int registerDate, byte[] internal); byte[] getInternal(); String getUserName(); int getRegisterDate(); @SuppressWarnings("deprecation") final String toString(); final String convertToString(); @Override int hashCode(); @Override boolean equals(Object obj); final static UserId valueOf(String userIdString); final static UserId fromString(String userIdString); final static UserId fromBytes(byte[] bytes);  }### Answer:
@Test public void testHashCode() { int max = 1000000; long startM =0, endM = 0l; startM = System.currentTimeMillis(); for ( int i=0; i<max; i++ ) { UserId userId = new UserId("test".concat(String.valueOf(i))); int h = userId.getRegisterDate()*31 + userId.getUserName().hashCode(); } endM = System.currentTimeMillis(); System.out.println("Use String.hashcode loop " + max +", time: " + (endM-startM)); startM = System.currentTimeMillis(); for ( int i=0; i<max; i++ ) { UserId userId = new UserId("test".concat(String.valueOf(i))); } endM = System.currentTimeMillis(); System.out.println("Use UserId.hashCode loop " + max +", time: " + (endM-startM)); }