Why does java.util.Properties implement Map<Object,Object> and not Map

后端 未结 5 570
死守一世寂寞
死守一世寂寞 2020-12-03 09:43

The java.util.Properties class is meant to represent a map where the keys and values are both Strings. This is because Properties objects are used

5条回答
  •  一生所求
    2020-12-03 09:53

    The reason: Liskov substitution principle and backwards compatibility. Properties extends Hashtable and thus must accept all messages that Hashtable would accept - and that means accepting put(Object, Object). And it has to extend plain Hashtable instead of Hashtable because Generics were implemented in the downwards-compatibe way via type erasure, so once the compiler has done its thing, there are no generics.

提交回复
热议问题