Calling generic methods
You are browsing legacy Javonet 1.5 (Java<>.NET bridge for Windows) documentation. Use the left side menu or click here to switch to latest Javonet 2.0 documentation. Javonet 2.0 allows you to use any module from
JVM, CLR, Netcore, Python, Ruby, Perl, NodeJS on Windows, Linux and MacOs
from any application created in Java, Clojure, Groovy, Kotlin, C#, F#, J#, VB.NET, Python, Perl, Ruby, JavaScript, TypeScript, C++ and GoLang
With Javonet you can very easily invoke any generic instance or static method. To call a generic method, you need to provide types that will be used during the method invocation. Those types can be passed as an instance of NType objects initialized with particular .NET types.
Assuming we have a custom any runtime with the following class inside:
To use generic methods from this class:
- Create an instance of our GenericSample class.
- Using the generic method, initialize the generic method invocation by passing one or many generic types of arguments.
- Invoke your method with a sample argument.
Javonet.getType(typeName) returns an instance of NType object attached to a specific .NET type. The instruction NType myType = Javonet.getType("String") is the Java equivalent of the .NET Type myType = typeof(String).
Was this article helpful?