3 ms·
Huh, I thought type annotations were unused at runtime. How can I enable runtime type checking?
by jchw 9y ago
Huh, I thought type annotations were unused at runtime. How can I enable runtime type checking?
- computerfriend 9y agoYou can't! Or, I guess you could do something hacky with the #!.
- hiram112 9y agoEven Java, which introduced generic types long after the language itself had become standardized and popular, cannot keep generic type information after compilation due to backwards compatibility. Don't quote me on it, but I believe C# doesn't have this problem.
- saagarjha 9y agoBut the compiler checks for this by default, so you'll get a warning unless you really break the type system.
- joshuamorton 9y agoThere are libraries that do magic to do this. Annotations are accessible at runtime, so you can do things like add an implicit import hook that decorates every function or class with a decorator that validates the annotations.