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);
     }
 }

Convert

val idField = new LongField(this)

to

val idField = new LongField[R](this)

If you do not specify the type R, then the LongField cannot check if the type is co-variant to Record[OwnerType] or not. Explicitly mentioning it should solve the purpose.

PS: I do not know the other class declaration to re-confirm, but the below declaration works:

case class Record[R]
class KeyedRecord[R] extends Record[R]
class LongField[OwnerType <: Record[OwnerType]](rec: OwnerType)
trait ID[R <: Record[R] with KeyedRecord[Long]] {
  this: R =>
  val idField = new LongField[R](this)
}
4

1 に答える 1