I have the following simple interface:
public interface ISimmilarityMeasure<T extends ResourceDescriptor> {
public double getSim(T s, T t);
}
and implementations like
public class NormalizedLevenstheinSim implements
ISimmilarityMeasure<SimpleResourceDescriptor> { ... }
and
public class JaccardCommentsSim implements
ISimmilarityMeasure<LabelsCommentsResourceDescriptor> { ... }
Both SimpleResourceDescriptor and LabelsCommentsResourceDescriptor extend
public abstract class ComparableResourceDescriptor
implements ResourceDescriptor
At runtime, I call the method
public static ISimmilarityMeasure<? extends ResourceDescriptor> getSimInstance(){ }
which will return an instance "sim" of ISimmilarityMeasure that relies on a specific instance of ResourceDescriptor.
I also create an array ResourceDescriptor[] candidates which will hold, at runtime, instances of the ResourceDescriptor type required by the specific ISimmilarityMeasure object.
However, if I try to call sim.getSim(candidates[0], candidates[1]) the compiler tells me that
"capture#3-of ? extends ResourceDescriptor ... is not applicable for the arguments (ResourceDescriptor ... "
I use eclipse and if I look at the available methods for sim, it shows me getSim(null s, null t).
I do not understand why this is the case. Should it not be clear to the compiler, that getSim has to expect any ResourceDescriptor and that every object in candidates is a ResourceDescriptor and therefore allow the call? Should it not be an exception at runtime if the specific ISimmilarityMeasure expects a certain type of ResourceDescriptor but is handed a different one?
sim()out there. You have shown us 3.double, and then in the middle it isISimmilarityMeasure<? extends ResourceDescriptor>.double getSim(T s, Tt)is the actual computation method of the interface.