enthuware.ocpjp.v11.2.3516
Posted: Sat Sep 18, 2021 5:25 am
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.
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.