如何將Double轉換爲Number,如下面的代碼所示?Double到Number
public Number parse(String text, ParsePosition status) {
// find the best number (defined as the one with the longest parse)
int start = status.index;
int furthest = start;
double bestNumber = Double.NaN;
double tempNumber = 0.0;
for (int i = 0; i < choiceFormats.length; ++i) {
String tempString = choiceFormats[i];
if (Misc.regionMatches(start, tempString, 0, tempString.length(), text)) {
status.index = start + tempString.length();
tempNumber = choiceLimits[i];
if (status.index > furthest) {
furthest = status.index;
bestNumber = tempNumber;
if (furthest == text.length()) break;
}
}
}
status.index = furthest;
if (status.index == start) {
status.errorIndex = furthest;
}
int c= 0;
return new Double(bestNumber);
}
但在Eclipse中它顯示
Type mismatch: cannot convert from Double to Number
其實這個代碼屬於從java.text
包ChoiceFormat.java
類。
這表明你在某處有不同的'Double'類型或不同的'Number'類型。你可以嘗試使用'java.lang.Number'聲明類型和'return new java.lang.Double(bestNumber);' – 2013-05-13 06:08:18
明確聲明我沒有在eclipse中得到任何這樣的錯誤 – 2013-05-13 06:08:35
你可以把[SSCCE ](http://sscce.org) – Ashish 2013-05-13 06:14:26