I have an interface with a method
public List< Object > getLeftBusinessObjects( List< Object > businessObjectIds, Object owningSystemId );
My implementation is:
public List<Object> getLeftBusinessObjects(List< Object > businessObjectIds, Object owningSystemId)
{
List<MyObject> myObjs= Helper.getMyObjects(businessObjectIds);
return myObjs;
}
Doing so I get the error:
Type mismatch: cannot convert from List<MyObject> to List<Object>
I have to double cast this way
return (List<Object>) (Object) myObjs;
to avoid the error.
Can someone explain me why? Why do I have to cast if all objects have per dafault Object as superclass?
A
List<MyObject>is not aList<Object>.,because otherwise you would be able to put anObjectinto aList<MyObject>try this