Forcing type parameter to implement specific method in java generics -
is there way force type parameter in java generics implement equals
method? example, wrote class: public class bag<item> implements iterable<item>
has contains
method, uses item.equals
method. want make sure passed object in generics implement equals
method.
you make abstract base class called itembase
, make equals abstract , have item extend itembase
.
public abstract class itembase { @override public abstract boolean equals(object o); } public class bag extends itembase
this force implementing itembase implement equals
Comments
Post a Comment