This discussion is archived
4 Replies Latest reply: Aug 5, 2010 5:19 PM by EJP RSS

Enforcing subclass type

843793 Newbie
Currently Being Moderated
I have the following structure

public interface IMy {...}
public interface IMyRepository {
public void addMy (IMy my);
}

public class My implements IMy {
}

public class SpecialMy extends My {
}

public class SpecialMyRepository implements IMyRepository {
=> public void addMy (...) {
}

Is there any way to enforce using generics that SpecialMyRepository always accepts SpecialMy object types and not My or any other IMy types?

Thanks,