I have a list:
private readonly IList<IList<GameObjectController>> removeTargets;
private readonly IList<IList<GameObjectController>> addTargets;
PickUp
inherits from GameObjectController
. But when I try this:
public IList<PickUp> Inventory
// ...
gameObjectManager.MoveFromListToWorld(this, user.Model.Inventory);
// ...
// This queues everything up to be removed, until ProcessMoves...() is called
public void MoveFromWorldToList(GameObjectController removedFromWorld, IList<GameObjectController> addTarget)
{
toBeRemoved.Add(removedFromWorld);
addTargets.Add(addTarget);
}
// ...
/// <summary>
/// Removes all the GameObjects on which removal is requested from the world.
/// </summary>
public void ProcessMovesFromListToWorld()
{
for (int i = 0; i < toBeAdded.Count; i++)
{
GameObjectController moved = toBeAdded[i];
addGameObjectToWorld(moved);
if (removeTargets[i] != null)
{
removeTargets[i].Remove(moved);
}
}
toBeAdded.Clear();
removeTargets.Clear();
}
I get a compiler error:
cannot convert from 'System.Collections.Generic.IList<PickUp>' to 'System.Collections.Generic.IList<GameObjectController>'
Why does this occur? Shouldn't this be fine, since PickUp
is a subclass of GameObjectController
? Do I need something like Java's Map<E extends GameObjectController>
?
Earlier, I was having a similar problem, where I was trying to implicitly cast inventory
from an IList
to an ICollection
. Is this the same problem?