I'm having an issue with trying to pass a double constant as a parameter into a hashmap.
public static final double Apple_Initial_Value = 30.0;
private static HashMap<String, Double> base_values = new HashMap<String, Double>() {{
put("Apple", Apple_Initial_Value);
}};
System.out.println(base_values.get("Apple"));
Results in the following output:
0.0
However,
public static final double Apple_Initial_Value = 30.0;
private static HashMap<String, Double> base_values = new HashMap<String, Double>() {{
put("Apple", 30.0);
}};
System.out.println(base_values.get("Apple"));
Results in the following output:
30.0
Having just finished a course in C, my mind jumped to it being some sort of pass by reference vs. pass by value issue, but as I understand it, java is only pass by value, so I'm at a loss.
Cheers, and thanks in advance!
Edit: My apologies, it looks like the code I posted above is not actually indicative of what is exactly happening in my code (as it's actually working!). To be more specific, the situation is broken into two classes, IR.java, and Main.java. The relevant parts of IR.java look like this:
public class IR {
public static final double Apple_Initial_Value = 30;
public static HashMap<String, Double> base_values = new HashMap<String, Double>() {{
put("Apple", Apple_Initial_Value);
}};
public static double get(String item) {
double value = (double) base_values.get(item);
return value;
}
}
And the relevant parts of Main.java look like this:
public class Main {
public static void main(String[] args) {
System.out.println(IR.get("Apple"));
}
}