About question enthuware.ocpjp.i.v11.2.3064

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
arnaldo
Posts: 1
Joined: Thu Jul 21, 2016 4:44 am
Contact:

About question enthuware.ocpjp.i.v11.2.3064

Post by arnaldo »

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>)?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About question enthuware.ocpjp.i.v11.2.3064

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests