doing objects in jjs

13 June 2015

Instantiating a Java Object in jjs is pretty straight forward, at least it can be.

var string = new java.lang.String("hello world");
//alternative
var stringClass = Java.type("java.lang.String");
var string = new stringClass("hello world");

This was so easy that I instantly continued trying Arrays.

//doing it javascript style
var arr=[];
arr[0]="hello";
arr[1]="world";
java.lang.String.join(" ",arr);
//doing it java style
var stringClass=java.lang.String.class;
var arr2==java.lang.reflect.Array.newInstance(StringClass,2);

You could argue that using the java style initialization doesn’t add anything and complicates stuff overly. But in realty sometime you need complex. Whenever you cannot rely on the automatic type casting system of jjs you have to do it manually.