Does IKVM.net not support generics (type parameters)?

I statically recompiled Java-lib, which used generics a lot, like Collection<?> , But the emitted .NET dll library uses Collection , not with type parameters. How so?

+6
java generics c # type-erasure ikvm
source share
1 answer

Java generators are processed by the Java compiler and converted to a non-standard version during compilation. This is different from .NET, where the CLR has first class support for type parameters. At the bytecode level, an ArrayList<T> will be just a simple ArrayList .

To quote Java docs :

Generalizations are implemented by the Java compiler as an interface transformation called erasure, which is a process of translating or rewriting code that uses generalizations into non-general code (i.e., compares the new syntax with the current JVM specification), in other words, this transformation destroys all the information of the general type; all information between angle brackets is erased. For example, LinkedList<Integer> will become LinkedList . Using variables of another type is replaced by the upper bound of the type variable (for example, Object ), and when the resulting code does not match the correct type, casting is added to the corresponding type.

+5
source share

All Articles