Java generics work one time, does not compile second time -
this accessor method collection in class abstractnode:
public list<polygonalchain> getoutedges() { return collections.unmodifiablelist(outedges); }
but following not work, compilation error message is: incompatible types: java.lang.object cannot converted .....formulaelements.polygonalchain
abstractnode anodeexample = getconnectingshape(); for(polygonalchain outedge: anodeexample.getoutedges()){ //do stuff }
what more confusing me, can use following code in descendants of abstractnode without error:
for(polygonalchain outedge: getoutedges()){ outedge.delete(); }
here minimal code, causes problem:
package brokengenerics; import java.math.biginteger; import java.util.list; public class brokengenerics { public static abstract class aclass <e extends number> { private list<b> bs; public list<b> getbs(){ return bs; } } public static class b extends aclass<biginteger>{ } public static aclass getsomething(){ return new b(); } /** * @param args command line arguments */ public static void main(string[] args) { for(b desc : getsomething().getbs())){ } } }
Comments
Post a Comment