简体   繁体   中英

Java: Generic Type type mismatch syntax error

I have this declaration/initiation written for Java JDK 1.6

Map<String, <? extends List<?>>> groupThemTogether = new HashMap<String, ArrayList<String[]>>();

The error happens at the first comma. The error message is

Type mismatch: cannot convert from HashMap<String,ArrayList<String[]>> to Map<String,List>

Why doesn't this compile?

You've got too many angle brackets. Try this:

Map<String, ? extends List<?>> groupThemTogether = new HashMap<String, ArrayList<String[]>>();

This compiles for me.

Are you sure of this?

This, similar code, compiles OK for me:

Map<String, ? extends List<?>> groupThemTogether = new HashMap<String, ArrayList<String[]>>();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM