0

I am woindering why this method

public V get(Object key) {

is not

public V get(K key) {

Thank you

serg.nechaev
  • 1,323
  • 19
  • 26

1 Answers1

1

The key may not strictly be of the type K. As long as the equals method contract is followed, any Object could be the key:

More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

M A
  • 71,713
  • 13
  • 134
  • 174