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