I feel stupid asking this but I am.
The line List<HasId> ids = list
is giving a compile error in the following code:
public class MyGarbageClass {
public void myMethod(List<MyCompany> list){
List<HasId> ids = list;
}
interface HasId {
int getId();
}
class MyCompany implements HasId{
private int id = 5;
@Override
public int getId() {
return id;
}
}
}
MyCompany implements HasId so I thought I should be able to assign it. Why cant I? And more importantly, what is an easy way to assign this to HasId list of objects.
update: List ids = (List<HasId>)list;
breaks also on inconvertible types