1- long xValue = someValue;
2- long yValue = someValue;
3- long otherTolalValue = (long)(xValue - yValue);
That line of code give me the following exception:
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Long.
Update :
code piece:
StackedBarChart sbc = new StackedBarChart();
XYChart.Series series = new XYChart.Series();
series.getData.add(new XYChart.Data("X1",150));
series.getData.add(new XYChart.Data("X2",50));
sbc.getData.add(series);
long dif = getDif(sbc);
long getDif(XYChart barChart){
XYChart.Series series = (XYChart.Series).getData().get(0);
// X1 at zero position i dont have to use iIterator now.
XYChart.Data seriesX1Data = series.getData().get(0);
XYChart.Data seriesX2Data = series.getData().get(1);
long x1Value = seriesX1Data.getYValue();
long x2Value = seriesX1Data.getYValue();
// line - 3 - exception on the next line
// -4- long value = (x1Value) - (x2Value);
long value = (long)(x1Value) - (long)(x2Value);
return value;
}
After debug i found that.
seriesX1Data,seriesX2Data contains double values as the passed chart has Number type but getYvalue() return long that is why program crash at runtime with that exception but when i cast in line why cast not succeed. i think that compiler see that the type already long !.
解决方案
It's impossible
long xValue = someValue;
long yValue = someValue;
long otherTolalValue = (long)(xValue - yValue);
neither of the 3 lines can produce java.lang.ClassCastException
Assuming someValues is Double,
Double someValue = 0.0;
it would give compile error: Type mismatch: cannot convert Double to long