public final class NetGenericHelper
extends java.lang.Object
NetObject, such as the generic delegates.
It offers the same logic used by NetObject: it reads the type arguments from the anonymous subclass
of a generic class (new Foo<Bar>() {}), builds the name of the closed CLR type and instantiates the
type arguments reflectively.
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
buildClosedClrName(java.lang.String openClrName,
java.lang.Class<?>[] typeArguments)
Builds the name of a closed generic CLR type, for example
System.Collections.Generic.List`1[System.Object]. |
static <X> X |
instantiate(java.lang.Class<?>[] typeArguments,
int index,
java.lang.Object nativeHandle)
Reflectively builds an instance of a type argument, wrapping a native handle returned from the bridge.
|
static java.lang.Class<?>[] |
resolveTypeArguments(java.lang.Class<?> instanceClass)
Returns the type arguments captured by the anonymous subclass, as in
new Foo<Bar>() {}. |
public static java.lang.String buildClosedClrName(java.lang.String openClrName,
java.lang.Class<?>[] typeArguments)
System.Collections.Generic.List`1[System.Object].
The name of each type argument is read from its public static className field.openClrName - the name of the open generic type, for example System.Collections.Generic.List`1typeArguments - the classes of the type argumentsjava.lang.IllegalArgumentException - if a type argument does not expose a public static className fieldpublic static <X> X instantiate(java.lang.Class<?>[] typeArguments,
int index,
java.lang.Object nativeHandle)
throws java.lang.Throwable
Object.X - the type of the instance to buildtypeArguments - the classes of the type argumentsindex - the position of the type argument to instantiatenativeHandle - the native object returned from the bridgejava.lang.Throwable - if the type argument has no public constructor accepting a single Object, or if that constructor failspublic static java.lang.Class<?>[] resolveTypeArguments(java.lang.Class<?> instanceClass)
new Foo<Bar>() {}.
The result is cached for each class.instanceClass - the class of the instance: it must be an anonymous subclass of a generic classjava.lang.IllegalArgumentException - if the instance was not created with the anonymous subclass syntax, or if a type argument is not a plain class