3 Replies Latest reply on May 14, 2011 9:20 PM by 852060

    How to Call Generic Method With Subclass Interface Implementation

      This is a rather complicated question just to explain!

      I have a class NOP extends ObjectPoint implements Copyable<NOP>. It has a subclass FacilityPoint extends NOP. I also have a utility class with a method public static <T extends Copyable<T>> void run(final T object) .

      When I try to call the run() method with a FacilityPoint argument, I get the error Bound mismatch: The generic method run(T) of type CopyTest is not applicable for the arguments (TrackPoint). The inferred type TrackPoint is not a valid substitute for the bounded parameter <T extends Copyable<T>>

      I asume I could fix this with a change to run()'s method signature, but can't figure out how. I tried <T extends Copyable<super T>> void run(final T object), but that didn't work. I also tried adding a delcaration to TrackPoint saying it implemented Copyable, but the compiler didn't like that either.

      Basically, I want to modify the run() method so it will accept an argument of an object which has a superclass that implements my Copyable interface. How do I do that?