我使用以下代码并添加了对大十进制和编译器显示的支持
为大十进制 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
的构造函数之前不能说别的了
关于java - 创建大十进制对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14799888/