Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java unchecked conversion

I have the following line of code

this.htmlSpecialChars = this.getSpecialCharMap();

where

private HashMap<String,String> htmlSpecialChars;

but I get a warning about an unchecked conversion. How do I stop this warning?

like image 438
Jim Jeffries Avatar asked Feb 24 '23 19:02

Jim Jeffries


2 Answers

You're getting this because getSpecialCharMap() is returning an object whose type cannot be verified by the compiler to be HashMap< String, String>. Go ahead and provide the prototype for getSpecialCharMap.

like image 185
broc Avatar answered Mar 03 '23 19:03

broc


You are getting the warning because the compiler cannot verify that the assignment to htmlSpecialChars is a HashMap<String,String>, since the method getSpecialChars() is returning a plain, non-generic HashMap.

You should modify your method to return the specific generic type:

private HashMap<String,String> getSpecialCharMap() {
    return new HashMap<String,String>();
    }
like image 25
Lawrence Dol Avatar answered Mar 03 '23 18:03

Lawrence Dol