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

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -