Note that there are some explanatory texts on larger screens.

plurals
  1. POLong to Double in Jexl
    text
    copied!<p>I use Jexl lib from apache and have some problems with using the <code>evaluate()</code> method of Expression class. Here is the code of NelderMead class:</p> <pre><code>import org.apache.commons.jexl2.*; public class NelderMead { // контсанты private static int M = 3; private static double E = 0.005; private static double A = 1.000; private static double B = 0.500; private static double Y = 2.000; // переменные private JexlEngine jexl; private Expression func; private String funcString = ""; private MapContext[] iterations; public NelderMead(){ this.jexl = new JexlEngine(); } public NelderMead(String funcString){ this.jexl = new JexlEngine(); this.setFunc(funcString); } public void setFunc(String funcString){ this.funcString = funcString; this.func = this.jexl.createExpression(funcString); } public double funcEval(MapContext args){ return ((Double) this.func.evaluate(args)).doubleValue(); } public boolean checkCriterian(){ return true; } } </code></pre> <p>And the code of testcase is:</p> <pre><code>import org.apache.commons.jexl2.MapContext; public class Test { /** * @param args */ public static void main(String[] args) { NelderMead nm = new NelderMead("(x1-2)^4+(x1-2*x2)^2"); MapContext mc = new MapContext(); mc.set("x1", 2); mc.set("x2", 1); System.out.println(nm.funcEval(mc)); } } </code></pre> <p>And when I run the testcase, it cause the following error:</p> <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double at NelderMead.funcEval(NelderMead.java:33) at Test.main(Test.java:14) </code></pre> <p>I can't understand why it can't cast to Double?</p> <p>PS</p> <p><a href="http://commons.apache.org/jexl/apidocs/org/apache/commons/jexl2/Expression.html#evaluate%28org.apache.commons.jexl2.JexlContext%29" rel="nofollow">Here</a> is the javadoc of evaluate() function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload