简体   繁体   中英

How do generics work in Gosu?

It has reified generics ... how is that implemented? Any significant difference from C#'s generics?

Difference from C# generics: for different instantiations of a generic class, C# generates classes at runtime. Gosu does not: one generic class corresponds to one class used at runtime. The type information is retained inside objects, not in classes. Thus, C# can specialize the code (eg for primitive types), while Gosu can not. For example, Gosu must wrap ints into objects to put them into a list.

Having only recent looked at Gosu, and not actually wrote any real programs in it yet; the best I can tell is that reified generics refers to the fact that Gosu is retaining the original type of the genricized object.

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.

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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