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.
enthuware.ocpjp.v11.2.3516
Moderator: admin
-
- Posts: 1
- Joined: Sat Sep 18, 2021 5:11 am
- Contact:
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: enthuware.ocpjp.v11.2.3516
You are right. Updated the problem statement to say "same or compatible declaration".
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Google [Bot] and 35 guests