>
1. Getting started
2. Working with Types
3. Working with Instances
4. Working with Fields
5. Advanced Activation and Licensing
To call Java instance methods from .NET you need to create an instance of Java object first. For that purpose you call Javonet.New(…) and pass the class name as argument. Next you get JObject as result which is a handle to the Java object. Now you can work on that object to invoke any Java method:
Sample Java code:
public class SampleJavaClass { public String SayHello(String name) { return "Hello " + name; } }
Example how to use it from .NET:
static void Main(string[] args) { // Todo: activate Javonet and add reference to the JAR file first //Creating instance of Java class JObject sampleClass = Javonet.New("SampleJavaClass"); //Calling instance methods String res = sampleClass.Invoke<String>("SayHello", "Student"); Console.WriteLine("Java method 'SayHello' returned: " + res); }
Download this article
Was this article helpful
Helpful for [] people