New Java Array of Strings in Nashorn -


i'm writing high-performance nashorn application, , i'd find equivalent new string[]{"foo", "bar", "noise"} within javascript. cost of converting javascript array java array prohibitively expensive, shows on every flame graph.

the best i've found point is: {var stringarray = java.type('java.lang.string[]');"); var arr = new stringarray(3)); var arr[0] = 'foo'; var arr[1] = 'bar'; var arr[2] = 'noise'; arr;}

but that's super ugly. best syntax available me?

thanks!

you can using java.to():

java.to(["foo", "bar", "noise"],"java.lang.string[]"); 

if code works (it me, tested jjs 1.8.0_51), can create function ease code readability. this:

function tojavastringarray(a) {   return java.to(a,"java.lang.string[]"); } 

Comments

Popular posts from this blog

javascript - Trigger mouseenter when an animated element touches mouse -

json - Zend error Connection -

java - Using Spring @Transactional with a combination of readOnly and write, when does this entity get committed? -