Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下のコードは、ジェネリックを特定のものにキャストするために Java プログラムに使用するものです。C# にはワイルドカードがないことは理解していますが、コードを Java に似たものに変更する方法として、誰かが正しい方向に向けてくれることを期待していました。
public <T extends GameComponent<?>>T getComponent(int id, Class<T> type){ return type.cast(components.get(id)); }
次のようになります。
public T GetComponent<T>(int id) where T : GameComponent { return components[id] as T; }
コメントの皆さん、解決策を修正するのを手伝ってくれてありがとう(私は道を外れていたので)。皆さんがいなければ、私はここにいられなかったでしょう。そして、私はあなたがいなくて寂しいです。
<3
しかし、本当に、ありがとう:D