7

I have a warning : Type safety: Unchecked cast from List < capture#10-of ?> to List < Object>

There is the call, stock.getListDVD().getListDVD() is an ArrayList<DVD>

jTablePanier=new JTableUt(stock.getListDVD().getListDVD(), DVD.class);

So i know the class it's a DVD.class

private ModelJTableUt model;    
public JTableUt(List<?> list, Class<?> classGen)
{               
    model=new ModelJTableUt((List<Object>) list, classGen); // <-- This line cause the warning, i convert List<?> to List<Object>
}

public ModelJTableUt(List<Object> list, Class<?> classGen) {

How can i resolve this warning without using

@SuppressWarning("unchecked")

Thanks a lot for your help. It save me many hours. The solution is

 public JTableUt(List<? extends Object> list, Class<?> classGen){
    model=new ModelJTableUt(list, classGen);
 }

 List<Object> list;
 public ModelJTableUt(List<? extends Object> list2, Class<?> classGen) 
 {
     list = new ArrayList<Object>();
 //I construct a new List of Object.    
     for (Object elem: list2)
     {
         list.add(elem);
     }
 }

mySQL Query - Selecting Fields

If I have mySQL table with 10 fields and I only need the to retrieve values of the some fields, is it advisable to use

SELECT field1, field2, field3 FROM...

rather than

SELECT * FROM...

I mean does it help retrieval / script execution faster if Im using [SELECT field1, field2, field3....]

4

1 回答 1

10

更改List<?> listList<? extends Object>

public JTableUt(List<?> list, Class<?> classGen)

来自Java 泛型教程

重要的是要注意List <Object>List<?> 不一样。您可以将 Object 或 Object 的任何子类型插入到 List<Object>. 但是您只能将null插入到List<?>.

于 2013-05-01T08:30:19.370 回答