List<> 的 Netbeans 未经检查的转换
Netbeans unchecked conversion for List<>
我正在学习 Netbeans 平台,并且正在学习本教程:
我已经达到 运行 原型的地步,但我在输出中收到以下警告 window:
warning: [options] bootstrap class path not set in conjunction with -source 1.6
warning: No processor claimed any of these annotations: javax.annotation.Generated
~/BDManager/CustomerViewer/src/org/shop/viewer/CustomerViewerTopComponent.java:53: warning: [unchecked] unchecked conversion
List<Employee> resultList = query.getResultList();
required: List<Employee>
found: List
3 warnings
我的EntityManager如下:
EntityManager entityManager = Persistence.createEntityManagerFactory("CustomerLibraryPU").createEntityManager();
Query query = entityManager.createNamedQuery("Employee.findAll");
List<Employee> resultList = query.getResultList();
for (Employee c : resultList){
jTextArea1.append(c.getFirstName()+" "+c.getLastName()+"\n");
}
参考本教程设计界面中的#4,而不是列表 List<Customer>
,我的列表是 List<Employee>
,因为实体 class 从 table 调用了我数据库中的员工。
如何摆脱这个警告?
这是因为 getResultList()
returns 您要分配给类型化列表(其中类型参数 = Employee)的非类型化列表(原始类型):
java.util.List getResultList()
Execute a SELECT query and return the query results as an untyped List.
关于泛型和原始类型的更多信息here。
要抑制该警告,您可以使用 @SuppressWarnings("unchecked")
。查看示例 here 和其他相关的 Whosebug 答案以了解如何操作。
我正在学习 Netbeans 平台,并且正在学习本教程:
我已经达到 运行 原型的地步,但我在输出中收到以下警告 window:
warning: [options] bootstrap class path not set in conjunction with -source 1.6
warning: No processor claimed any of these annotations: javax.annotation.Generated
~/BDManager/CustomerViewer/src/org/shop/viewer/CustomerViewerTopComponent.java:53: warning: [unchecked] unchecked conversion
List<Employee> resultList = query.getResultList();
required: List<Employee>
found: List
3 warnings
我的EntityManager如下:
EntityManager entityManager = Persistence.createEntityManagerFactory("CustomerLibraryPU").createEntityManager();
Query query = entityManager.createNamedQuery("Employee.findAll");
List<Employee> resultList = query.getResultList();
for (Employee c : resultList){
jTextArea1.append(c.getFirstName()+" "+c.getLastName()+"\n");
}
参考本教程设计界面中的#4,而不是列表 List<Customer>
,我的列表是 List<Employee>
,因为实体 class 从 table 调用了我数据库中的员工。
如何摆脱这个警告?
这是因为 getResultList()
returns 您要分配给类型化列表(其中类型参数 = Employee)的非类型化列表(原始类型):
java.util.List getResultList()
Execute a SELECT query and return the query results as an untyped List.
关于泛型和原始类型的更多信息here。
要抑制该警告,您可以使用 @SuppressWarnings("unchecked")
。查看示例 here 和其他相关的 Whosebug 答案以了解如何操作。