2013-02-10 80 views
1

我使用下面的代碼,我添加了對大十進制的支持和編譯器顯示 錯誤創建對象爲大小數new BigDecimal(nextRandom),我該如何克服它?錯誤創建大小數對象

所有其他類型都按預期工作。

public static SwitchInputType<?> switchInput(final String typeName, final String memberName, final int cnt, boolean random) { 
... 
} else if (typeName.equals("decimal") || (typeName.equals("java.math.BigDecimal"))) { 
    BigDecimal nextRandom = RandomizeValues.nextRandom("9"); 
    return new SwitchInputType<BigDecimal>(new BigDecimal(nextRandom));<-HERE IS THE ERROR 

} else if (typeName.equals("boolean")) { 
    boolean randomBoolean = RandomizeValues.nextRandom(); 
    return new SwitchInputType<Boolean>(new Boolean(randomBoolean)); 
} 

的錯誤是:

The constructor BigDecimal(BigDecimal) is undefined 

我應該怎樣解決呢?

+2

構造請把你的示例代碼下降到最低** **證明編譯器錯誤需要。 – 2013-02-10 16:33:17

+1

和什麼是錯誤? – ogzd 2013-02-10 16:34:01

+0

爲什麼要創建另一個BigDecimal對象的BigDecimal對象?似乎多餘 – 2013-02-10 16:35:00

回答

6

你正在創建

new BigDecimal(nextRandom) 

其中nextRandomBigDecimal。這是沒有意義的。

替換行

return new SwitchInputType<BigDecimal>(new BigDecimal(nextRandom)); 

return new SwitchInputType<BigDecimal>(nextRandom); 

,並檢查是否仍然出現同樣的錯誤。

不能說別的,直到我看到的SwitchInputType