折腾:
【未解决】VSCode中调试java报错:Build failed do you want to continue
期间,看到很多警告:
ContinuousAddressBuilder is a raw type. References to generic type ContinuousAddressBuilder<T> should be parameterized
点击看到代码是:
src/refer/java/iec_analysis/src/main/java/com/iec/assemble101/ContinuousAddressBuilder.java
public ContinuousAddressBuilder builderCon(int con) { this.con = con; return this; }
is a raw type References to generic type should be parameterized
去找到源码是:
src/refer/java/iec_analysis/src/main/java/com/iec/assemble101/ContinuousAddressBuilder.java
public class ContinuousAddressBuilder<T> extends VariableLengthPacket {
去搜此处项目中没有
extends ContinuousAddressBuilder
感觉此处不是很理解 语法和业务逻辑,不太会改代码
再去搜:
extends VariableLengthPacket
只有此处2个类用到了:
public class ContinuousAddressBuilder<T> extends VariableLengthPacket {
没有其他extends VariableLengthPacket的类了。
所以,感觉只能改为:
// public ContinuousAddressBuilder builderCon(int con) { public ContinuousAddressBuilder<VariableLengthPacket> builderCon(int con) {
但是却又报其他错了:
Type mismatch: cannot convert from ContinuousAddressBuilder<T> to ContinuousAddressBuilder<VariableLengthPacket>Java(16777235)
说是可以关掉此警告:
@SuppressWarnings(“rawtypes”)
参考:
“If there are multiple types of objects in your list than you can use a wildcard:
List<?> synchronizedpubliesdList = Collections.synchronizedList(publiesdList);”
试了试问号
public ContinuousAddressBuilder<?> builderCon(int con) {
语法上,倒是没有报错了:
不过貌似此处,不算是多个类型,而同一时刻只能有一个类型的
另外,去
Command+鼠标点击 T 看到定义:
-》可见:
当前类ContinuousAddressBuilder,之所以用了 <T>
是因为:内部有些变量或函数,支持多种变量类型:
/** * 信息体元素。 * 包含多个元素,只接受int、float、double类型数据 */ private ArrayList<T> informosomes; public ContinuousAddressBuilder addInformosome(T informosome) { this.informosomes.add(informosome); return this; }
-》所以此处类也是T
看到当前输入的变量是int,尝试改为:
public ContinuousAddressBuilder<int> builderCon(int con) {
结果报错:
去找找java中int的类型,或许是大写的Int? 或Integer ?
@SuppressWarnings("unchecked")
List<String> publiesdList = new List<String>();
此处的String,就是我所说的类型
Java int
“int与Integer的基本使用对比
Integer是int的包装类;int是基本数据类型;
Integer变量必须实例化后才能使用;int变量不需要;
Integer实际是对象的引用,指向此new的Integer对象;int是直接存储数据值 ;
Integer的默认值是null;int的默认值是0。”
此处java中int和Integer还是不一样的
无意间改为:
public ContinuousAddressBuilder<T> builderCon(int con) {
就没了警告了:
所以都去改为加上 <T>
【总结】
此处把代码:
public ContinuousAddressBuilder builderCon(int con) {
改为:
public ContinuousAddressBuilder<T> builderCon(int con) {
即可解决警告问题。
转载请注明:在路上 » 【已解决】VSCode中java代码警告:is a raw type References to generic type should be parameterized