About question enthuware.ocpjp.i.v11.2.3064
Posted: Mon Jul 15, 2019 5:24 am
Given:
System.getProperties() returns a Properties object. Properties class extends HashTable. HashTable class implements Map interface. Map has a method named entrySet(), which returns Set<Map.Entry<K,V>>. Therefore, x is typed to Map.Entry<Object, Object> here and m is typed to Object.
and
Map has a method named keySet(), which returns Set<K>. Therefore, x is typed to Object and so, x.length() will not compile. It will work if this is changed to : System.out.println(x);
why in the first case x is typed to Map.Entry<Object, Object> while in the second case x is typed to Object (and not Set<Object>)?
System.getProperties() returns a Properties object. Properties class extends HashTable. HashTable class implements Map interface. Map has a method named entrySet(), which returns Set<Map.Entry<K,V>>. Therefore, x is typed to Map.Entry<Object, Object> here and m is typed to Object.
and
Map has a method named keySet(), which returns Set<K>. Therefore, x is typed to Object and so, x.length() will not compile. It will work if this is changed to : System.out.println(x);
why in the first case x is typed to Map.Entry<Object, Object> while in the second case x is typed to Object (and not Set<Object>)?