I don't understand why this line is not causing a compile time error when get() function is expecting a String object and I am passing a char type.
int integer = romanValues.get(roman.charAt(roman.length() - 1));
This is my whole program:
import java.util.Map;
import java.util.HashMap;
public class Algorithm {
public static void romanToInteger(String roman) {
Map<String, Integer> romanValues = new HashMap<>();
romanValues.put("I", 1);
romanValues.put("V", 5);
romanValues.put("X", 10);
romanValues.put("L", 50);
romanValues.put("C", 100);
romanValues.put("D", 500);
romanValues.put("M", 1000);
int integer = romanValues.get(roman.charAt(roman.length() - 1));
}
public static void main(String[] args) {
Algorithm.romanToInteger("XII");
}
}