Java generics: Bound mismatch.Looking for the valid substitute -
i have couple of generic classes:
public interface data<e> {} public interface clonable<e extends clonable<e>> {} public interface naturalnumberinterface extends data<naturalnumberinterface> {} public class naturalnumber implements naturalnumberinterface {} public interface setinterface<e extends data<e>> extends clonable<setinterface<e>> {} public class set<e extends data<e>> implements setinterface<e> {}
when i'm trying create new instance of set set<naturalnumber> s=new set<naturalnumber>();
compiler says:
naturalnumber
not valid substitute type parameter<e extends data<e>>
of typeset<e>
maybe can me find mistake, cause spent long time , didn't find solution.
i assume setinterface
defined in same way listinterface
, data
interface data<t>
.
the generic argument of setinterface
f-bounded: e extends data<e>
. in current code naturalnumber
type extends data<naturalnumberinterface>
. if e
naturalnumber
, condition violated should extend more specific type data<naturalnumber>
.
you should use f-bounds naturalnumberinterface
well:
public interface naturalnumberinterface<t extends naturalnumberinterface<t>> extends data<t> public class naturalnumber implements naturalnumberinterface<naturalnumber>
this way work.
Comments
Post a Comment