简体   繁体   English

仿制药如何在Gosu中运作?

[英]How do generics work in Gosu?

It has reified generics ... how is that implemented? 它已经确定了泛型......这是如何实现的? Any significant difference from C#'s generics? 与C#的泛型有什么重大区别?

Difference from C# generics: for different instantiations of a generic class, C# generates classes at runtime. 与C#泛型的区别:对于泛型类的不同实例,C#在运行时生成类。 Gosu does not: one generic class corresponds to one class used at runtime. Gosu没有:一个泛型类对应于运行时使用的一个类。 The type information is retained inside objects, not in classes. 类型信息保留在对象内,而不是类中。 Thus, C# can specialize the code (eg for primitive types), while Gosu can not. 因此,C#可以专门化代码(例如,对于原始类型),而Gosu则不能。 For example, Gosu must wrap ints into objects to put them into a list. 例如,Gosu必须将int包装成对象以将它们放入列表中。

Having only recent looked at Gosu, and not actually wrote any real programs in it yet; 最近才看过Gosu,并没有真正写过任何真正的程序; the best I can tell is that reified generics refers to the fact that Gosu is retaining the original type of the genricized object. 我能说的最好的是,具体化的仿制品指的是Gosu保留了原始类型的格式化对象。

In Java there is no way without resorting to reflection to find out what the original type of something passed into a generic function is. 在Java中,没有办法不使用反射来找出传递给泛型函数的原始类型。

Look at the bottom of this page in the documentation. 请查看文档中此页面的底部。 It does not say actually how to do it, but just that it can. 它实际上并没有说明如何做到这一点,只是它可以。

Also take a look at these questions: 另请看一下这些问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM