How Javonet 1.2 Can Impress You?


Changes are coming

We have just released updated Javonet 1.2. New version includes several internal improvements as well as great new features.

Getting Faster

javonet_overhead_compareWith each release we try to add one more brick in our chase for highest performance. We are working hard to reach performance as close as possible to native code executions time in .NET. By overhead we defined the additional time consumed by javonet in execution of .NET code. The overhead is calculated by substracting time taken by execution of certain logic in .NET from time taken by execution of same logic from Java using Javonet.

javonet_overhead_vs_wsIn latest release Javonet 1.2 we have decreased the overhead by incredible 83%. Overhead varies depending on type of instructions being called and in some cases it is optimized by our internal execution optimization engine. Currently the lowest overhead we have reached is at level of 30%. In the diagram on the right you can see the comparison of Javonet 1.2 to 1.0 overhead and the diagram on the left side depicts the outstanding results in comparison to Web Services.

Support for generic methods<T>

With new release we have introduced support for generic methods invocation. Now using Javonet you can easily call generic methods with single or multiple generic parameters. Thanks to our fluent API all you need to do is prefixing your “invoke” method call with “generic” method where you pass types to be used as generic arguments. Types for generic method arguments can be resolved using known “Javonet.getType(typeName)” operation.


You can read more about calling generic methods in our quick start guide: Calling generic methods

“ref” and “out” allowed

Responding to your requests we have implemented support for “ref” and “out” keywords. Now you can call any method expecting arguments to be passed by reference. Implemented mechanism supports both passing primitive types and other .NET objects or arrays of them. Modifications applied within .NET method body to argument passed by reference will be automatically reflected on local variables on Java side. Check simple example based on “bool Int32.TryParse(string,out int)” and read more in our quick start guide:

 String strNumber = "4";
 AtomicReference<Integer> myInt=new AtomicReference<Integer>();

 //NOut constructor with argument type is used because myInt has NULL value. Without specifying explicitly 
 //argument type .NET would not be able to locate proper method to execute.
 if (Javonet.getType("Int32").invoke("TryParse",strNumber,new NOut(myInt,"System.Int32")))

More details: Passing arguments by reference with ref or out keywords

Type Specific Null

Let’s consider the case in which we have two following methods on .NET side:

class SampleType
   public void Method(String arg1)
   public void Method(MyClass arg1)

If you want to call method SampleType.Method passing null as argument, .NET side wan’t be able to locate the method to be called. Therefore we have introduced type-specific nulls. Now you can differentiate calls to this method in following way:

NObject myObj = Javonet.New("SampleType");
myObj.invoke("Method",new NNull("String")); //Method with string argument called passing null as value of arg1
myObj.invoke("Method",new NNull("MyClass")); //Method with MyClass argument called passing null as value of arg1

Other Improvements

Among those big changes we have also added some minor modifications these include:

  • Support for passing NType as method argument to allow invocation of methods expecting Type
  • Added auto namespace resolver for declaring NEnum variable, now you can just provide type name and if there is only one type matching Javonet will find it! (ex. new NEnum(“DialogResult”,”OK”))
  • Extended method resolver to support finding methods defined on all interfaces inherited by target object. Now you can easily iterate through IEnumerable collections by calling “GetEnumerator” and “MoveNext”
  • Extended fields resolver with support to find fields and properties defined on all interfaces inherited by target object.
  • Improved errors messages to provide more meaningful details
  • Fixed arrays passing issue

Your Feedback Counts

We are constantly working to improve the tool, nevertheless you use trial, academic or commercial license please let us know through email or comments what else you would like to get improved in Javonet or our training materials. We greatly appreciate your feedback!