Page 1 of 1

enthuware.ocpjp.v11.2.3516

Posted: Sat Sep 18, 2021 5:25 am
by Jur_Aj
Hello,

yeasterday I tried this question :

Given: Map<String , List<? extends CharSequence>> stateCitiesMap = new HashMap<String, List<? extends CharSequence>>(); Which of the following options correctly achieves the same declaration using type inference?

Correct answers according to enthuware are :

Map<String , List<? extends CharSequence>> stateCitiesMap1 = new HashMap<>();
and
var stateCitiesMap2 = new HashMap<String, List<? extends CharSequence>>();

Well, seems ok, but the second stateCitiesMap will be HashMap and not Map.

So if you do

HashMap<String , List<? extends CharSequence>> x = stateCitiesMap1; // will not compile
HashMap<String , List<? extends CharSequence>> y = stateCitiesMap2; // will compile

are those two answers really correct ?

Thanks.

Re: enthuware.ocpjp.v11.2.3516

Posted: Sun Sep 19, 2021 9:32 am
by admin
You are right. Updated the problem statement to say "same or compatible declaration".

thank you for your feedback!