Trating警告:[rawtypes]发现原始类型:Netbeans中的JList(更改对象类型以满足新的Java 7标准)

时间:2022-01-20 17:04:07

I'm working on Netbeans and Netbeans has some auto generated object declaration for controllers and some variables. I kept getting the following warnings in the build time. Then I realized from my previous question that Since Java 7, DefaultListModel, JList, Set ... are generic types and need to be provided with their associated type. How come Netbeans didn't generate files to conform with Java7 expectations?! And how can I change code in the auto generated sections to meeet those new conditions?!

我正在研究Netbeans和Netbeans有一些自动生成的控制器和一些变量的对象声明。我在构建时间内不断收到以下警告。然后我从我之前的问题中意识到,由于Java 7,DefaultListModel,JList,Set ...是泛型类型,需要提供它们的关联类型。为什么Netbeans没有生成符合Java7期望的文件?!如何更改自动生成的部分中的代码以满足这些新条件?!

C:\Documents and Settings\...somefile.java:902: warning: [rawtypes] found raw type: JList
private javax.swing.JList jList_SystemDSNList;
missing type arguments for generic class JList<E>
where E is a type-variable:
E extends Object declared in class JList

For instance how can I change

例如,我该如何改变

private javax.swing.JList jList_DataSetList;

into this,

private javax.swing.JList<E> jList_DataSetList;

When this field is in blue and protected???!! I can change the variable name but it doesn't allow me to change the type!

当这个字段是蓝色并保护??? !!我可以更改变量名称,但它不允许我更改类型!

2 个解决方案

#1


3  

Select the object in the designer, go to the properties, and select the Code section.

在设计器中选择对象,转到属性,然后选择“代码”部分。

Under "Type Parameters" enter the type you want to declare you list with. Eg. <E> or <String>

在“类型参数”下,输入要声明的列表类型。例如。

If you right-click the object in the designer, and select Customize Code, you can see that declaration and instantiation now include the type parameter.

如果右键单击设计器中的对象,并选择“自定义代码”,则可以看到声明和实例化现在包含type参数。

#2


0  

I guess instead of you should provide the data type your JList object is going to store, I don't think any IDE prevent you from changing the source code.

我想你应该提供你的JList对象要存储的数据类型而不是你应该存储,我认为任何IDE都不会阻止你更改源代码。

#1


3  

Select the object in the designer, go to the properties, and select the Code section.

在设计器中选择对象,转到属性,然后选择“代码”部分。

Under "Type Parameters" enter the type you want to declare you list with. Eg. <E> or <String>

在“类型参数”下,输入要声明的列表类型。例如。

If you right-click the object in the designer, and select Customize Code, you can see that declaration and instantiation now include the type parameter.

如果右键单击设计器中的对象,并选择“自定义代码”,则可以看到声明和实例化现在包含type参数。

#2


0  

I guess instead of you should provide the data type your JList object is going to store, I don't think any IDE prevent you from changing the source code.

我想你应该提供你的JList对象要存储的数据类型而不是你应该存储,我认为任何IDE都不会阻止你更改源代码。