KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Please consider the following snippet: public interface MyInterface { public int getId(); } public class MyPojo implements MyInterface { private int id; public MyPojo(int id) { this.id = id; } public int getId() { return id; } } public ArrayList<MyInterface> getMyInterfaces() { ArrayList<MyPojo> myPojos = new ArrayList<MyPojo>(0); myPojos.add(new MyPojo(0)); myPojos.add(new MyPojo(1)); return (ArrayList<MyInterface>) myPojos; } The return statement does a casting that doesn't compile. How can I convert the myPojos list to the more generic list, without having to go through each item of the list ? Thanks
Tags (comma-separated)
Save Edits
Cancel