I apologize if this is a common question but I could not seem to find the proper set of search terms that yielded an answer.
Basically I have an RMI application and on the 'middle-tier' I would like to pass around references to the implementation objects and only convert to the interface type when dealing with them over RMI (I never pass an object back to the middle-tier).
public interface Questionnaire implements Remote {
public List<? extends Comment> getComments() throws RemoteException;
}
public class QuestionnaireImpl extends UnicastRemoteObject implements Questionnaire {
public List<CommentImpl> getComments() {...}
}
This works fine, the issue arises when I try to do the following:
public List<Comment> getComments(int questionnaireId) throws RemoteException {
return classLoader.getQuestionnaire(questionnaireId).getComments();
}
The compiler issues a Type mismatch: cannot convert from List<capture#8-of ? extends Comment> to List<Comment> Which I find perplexing as the compiler can assure that at the very least it is a List of Comment objects.