错误创建大小数对象
问题描述:
我使用下面的代码,我添加了对大十进制的支持和编译器显示 错误创建对象为大小数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
我应该怎样解决呢?
答
你正在创建
new BigDecimal(nextRandom)
其中nextRandom
是BigDecimal
。这是没有意义的。
替换行
return new SwitchInputType<BigDecimal>(new BigDecimal(nextRandom));
与
return new SwitchInputType<BigDecimal>(nextRandom);
,并检查是否仍然出现同样的错误。
不能说别的,直到我看到的SwitchInputType
构造请把你的示例代码下降到最低** **证明编译器错误需要。 – 2013-02-10 16:33:17
和什么是错误? – ogzd 2013-02-10 16:34:01
为什么要创建另一个BigDecimal对象的BigDecimal对象?似乎多余 – 2013-02-10 16:35:00