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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -