Java generics type conversion -


here's sample code:

public static baselistadapter<? extends item> getlistadapter() {     ... }  ...  public class myclass<t extends item> {     ...     baselistadapter<t> adapter = (baselistadapter<t>) getlistadapter();     ... } 

the compiler complains there's unchecked cast.

java: unchecked cast   need: baselistadapter<t>   found:    baselistadapter<capture#1, ? extends item> 

i want know why warning produced , how resolve it.

this because while baselistadapter accepts type extending item, you're explicitly casting baselistadapter ol' type baselistadapter type t, not same type, hence error.

if want fix it, need avoid cast altogether , manage item instead or make baselistadapter handle t , not unnamed type ? extends item.


Comments