java - Using generics in method: exception in compilation: complaining about type :cannont convert to -


the code below throws exception in "return list;" typemismatch . suposed not to.

public class teste {      public <s extends testpai> s getlist(){         testpai list = new testefilho();         return  list;     } }  class testefilho implements testpai{  }  interface testpai{  } 

i found soluction it, puting this

public class teste { @suppresswarnings("unchecked")     public <s extends testpai> s getlist(){         testpai list = new testefilho();         return  (s)list;     } }  class testefilho implements testpai{  }  interface testpai{  } 

but sounds weird , since have other codes compiled before arent performing that. - im using eclipse ide in windows machine jre1.7.0_51 execution environment.

can make works expected (in first code).

thanks in advance.

all types fixed! you're not using type parameter @ all. simplest way just

public testpai getlist(){     testpai list = new testefilho();     return  list; } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -