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>)?
About question enthuware.ocpjp.i.v11.2.3064
Moderator: admin
-
- Posts: 1
- Joined: Thu Jul 21, 2016 4:44 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About question enthuware.ocpjp.i.v11.2.3064
entry set returns Set<Map.Entry<K,V>> ==> Map.Entry<Object, Object>
key returns Set<K> => Object.
Observe the type specification of both the sets. The first one is Map.Entry<K, V> and the second one is just K.
key returns Set<K> => Object.
Observe the type specification of both the sets. The first one is Map.Entry<K, V> and the second one is just K.
Who is online
Users browsing this forum: No registered users and 9 guests