Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload