3 ms·
We don't work around Java type erasure: if you create some object in Java and pass it off to Gosu, then that information is lost. For Gosu classes that are re
by akeefer 16y ago
We don't work around Java type erasure: if you create some object in Java and pass it off to Gosu, then that information is lost. For Gosu classes that are reified, we actually store the type parameter on the object itself, and it becomes an implicit constructor argument. For generified functions, we pass the type parameter through that's determined statically by the parser. For enhancements on generified Java classes, we also pass through the statically-determined type parameter. I.e. if you have a Gosu class Foo generified on T, when you construct Foo with type param String we'll pass the String type through to the constructor and store it on the object instance so we can retrieve it later. If you have something the compiler thinks is a List of Objects, and you call an enhancement method on List, we'll pass through Object as the type parameter, even if at runtime it's actually a List of Strings. So it's not perfect in its interaction with Java code, but it's usually good enough (and better than losing it entirely). As far as the Java classes we generate go, your generic type Foo has only one class, but as far as Gosu's type system goes, Foo parameterized on Object is a separate type instance from Foo parameterized on String.