KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Well, I have a class Customer (no base class). I need to cast from LinkedList to List. Is there any clean way to do this? Just so you know, I need to cast it to List. No other type will do. (I'm developing a test fixture using Slim and FitNesse). EDIT: Okay, I think I need to give code examples here. import java.util.*; public class CustomerCollection { protected LinkedList<Customer> theList; public CustomerCollection() { theList = new LinkedList<Customer>(); } public void addCustomer(Customer c){ theList.add(c); } public List<Object> getList() { return (List<? extends Object>) theList; } } So in accordance with Yuval A's remarks, I've finally written the code this way. But I get this error: CustomerCollection.java:31: incompatible types found : java.util.List<capture#824 of ? extends java.lang.Object> required: java.util.List<java.lang.Object> return (List<? extends Object>)theList; ^ 1 error So, what's the correct way to do this cast?
Tags (comma-separated)
Save Edits
Cancel