:
3):
public int hashCode() {
return Objects.hashCode(name);
}
, .
4.) , , . -, String, String . , 4:
Map<Key, Value> map;
map.put(key, value);
Value value = map.get(key);
Map<String, Value> map;
map.put(key.getName(), value);
Value value = map.get(key.getName());
( , "" Key , - . )
5.) , -. java.lang.String:
public final class String
implements java.io.Serializable, Comparable<String>, CharSequence {
...
private int hash;
, , . , Map "" , , , , t.
, , , , , , - :
class Key
{
private final String name;
...
private final int hashCode;
Key(String name, ...)
{
this.name = name;
...
this.hashCode = computeHashCode();
}
private int computeHashCode()
{
int result = 31;
result = 31 * result + Objects.hashCode(name);
result = 31 * result + ...
return result;
}
}