Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this possible? : HashMap<String, char>

I'm creating a game with two boards: http://imgur.com/nrCX5Ux

I want to link the "A" to the ".". Both are string Arrays. I want to use this:

indexesOfBoard.put("A", ((morris.START[0].charAt(0))));

But then I get an error like:

The method put(String, String) in the type HashMap<String,String> is not applicable for the arguments (String, char)

And if I change the HashMap to < String, char> I'll get:

Syntax error on token "char", Dimensions expected after this token
like image 678
Olivier Avatar asked Jan 09 '14 12:01

Olivier


3 Answers

Type arguments cannot be primitive types. Use wrapper class alternative instead:

HashMap<String, Character>
like image 83
Rohit Jain Avatar answered Oct 04 '22 18:10

Rohit Jain


Primitive type is not allowed in generic class, only class type is allowed. use like this.

HashMap<String, Character>
like image 34
Qadir Hussain Avatar answered Oct 04 '22 17:10

Qadir Hussain


You cannot use primitive types in generics. Use Character instead.

like image 37
Aniket Thakur Avatar answered Oct 04 '22 17:10

Aniket Thakur