Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cannot Cast List<? extends Object> as List<Object>

807591May 6 2008 — edited May 6 2008
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 3 2008
Added on May 6 2008
2 comments
2,158 views