Working on a group project for school, and the following line throws an error when I run javac in the command line.
Object result = engine.eval(equation); //evaluate the arithmetic expression
cellValue = (double) result; // <-- This throws a compiler error (obviously)
But for some reason, this compiles and works(!) in eclipse, which my groupmates are using. I tried it for myself to confirm because I couldn’t believe it.
ScriptEngine engine = manager.getEngineByName("JavaScript");
engine is a ScriptEngine, if that’s relevant at all. I can’t for the life of me figure out how eclipse’s compiler is allowing a line to be compiled that casts an Object directly to a double.
Probably your friends are using another version of the Java language. The cast of
Objecttodouble(the primitive type) seems to be legal in Java 7, but not in Java 6. You can have your friends change their project settings in Eclipse or update your compiler to the version 7.Note that casting
ObjecttoDouble(the class) works in both versions.