Java unchecked conversion

25,400

Solution 1

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.

Solution 2

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>();
    }
Share:
25,400
Jim Jeffries
Author by

Jim Jeffries

Software developer - mostly working with ruby, javascript and mongoDB at the moment, but have experience with Java, C#, C++, Oracle, Postgres, SQL Server and Python and dabble in Neo4J, Clojure, Haskell, Scala, Go and whatever else takes my fancy.

Updated on March 16, 2020

Comments

  • Jim Jeffries
    Jim Jeffries about 4 years

    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?