I have a java program which runs properly.
But when I try to clean and build it in Netbeans it is choking on this line:
protected HashMap<String, ArrayList<HashMap<String,String>>> config1
config1 = new <String,ArrayList<HashMap<String,String>>> HashMap(); // build breaks here.
the error is:
cannot find symbol
symbol : constructor
<java.lang.String,java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.String>>
>HashMap()
You are placing your type parameters in wrong place. It comes in between HashMap
and the ()
: -
config1 = new HashMap<String,ArrayList<HashMap<String,String>>>();
Also, its a good idea to have more generalized types rather than specific types in the declaration, and even in generic type parameters
. So you should use Map
instead of HashMap
in declaration, and List
instead of ArrayList
in your type parameter
: -
And actually, you don't need to break your declaration and initialization in two lines. Just have them in one single line. It looks more cleaner. So, you can change your two lines to: -
protected Map<String, List<Map<String,String>>> config1 =
new HashMap<String, List<Map<String,String>>>();
您必须将类名放在泛型之前。
config1 = new HashMap<String,ArrayList<HashMap<String,String>>>();
Generics should follow the class name. It should not be used before the class name. Correct your second line as below:
protected HashMap<String, ArrayList<HashMap<String,String>>> config1;
config1 = new HashMap <String,ArrayList<HashMap<String,String>>>();
你可以试试这个:
config1 = new HashMap<String, ArrayList<HashMap<String, String>>>(); // build breaks here.
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.