作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不明白我在这里做错了什么,因为我收到错误:“无法实例化 BigInteger 类型”
public static <BigInteger> List<BigInteger> convertIntegerListToStringList(List<String> existingList) {
ArrayList<BigInteger> newList = new ArrayList<BigInteger>();
for(String item : existingList) {
newList.add(new BigInteger(item));
}
return newList
}
破坏代码的部分是 public static <BigInteger>
输入参数...但我不知道为什么。当我删除这个类型参数时,编译错误就会消失。
最佳答案
删除单独的<BigInteger>
从你的方法签名。该语法用于声明类型变量,这在您的情况下是不必要的。正如所写,您正在声明一个名为 BigInteger
的“占位符”代表某种未知类型。在该方法中,BigInteger
引用该未知类型(由于未知,无法实例化)而不是引用 java.math.BigInteger
如您所愿。
此外,您应该重新访问您的方法名称:您的方法执行与名称所示相反的操作,即将字符串列表转换为 BigInteger 列表,而不是相反。
关于java - 如何在这样的 java 静态方法中实例化 BigInteger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23934511/
我是一名优秀的程序员,十分优秀!