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

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -