Search code examples
javajava-6value-ofjdk1.4

The method valueOf(String) in the type Integer is not applicable for the arguments (int)


I am getting an error The method valueOf(String) in the type Integer is not applicable for the arguments (int) for the below line when I compile the code in jdk1.4(j2sdk1.4.1_05). If I compile the same code in jdk1.6.0_14, the code works fine.

HashMap offMap = new HashMap(); offMap.put("price", Integer.valueOf(offer.getPrice()));

My question is why this code is giving error when compiled in jdk1.4 and not in jdk1.6. Any suggestions to get in compiled?

Note: This is pre-written code. Need your suggestion for code change and get it compiled without errors.


Solution

  • For Java 1.4, I think you want the Integer(int) constructor like

    offMap.put("price", new Integer(offer.getPrice()));
    

    Integer.valueOf(int) wasn't available in Java 1.4 (the Javadoc says it was added in Java 1.5).