Question

In Java's Nashorn engine, when you eval code, if you do this

var e = Packages.org.bukkit["event"]

e will be null.

But, one thing that I found, is that if I do this

var anothervar = Packages.org.bukkit.event
var e = Packages.org.bukkit["event"]

e (as well as anothervar) will be the org.bukkit.event package.

Why does Nashorn have it so after I access a package with dot notation, it will start working with the bracket notation?

Was it helpful?

Solution

From what I am looking at, it is a Java 8 bug, so in the meantime, a hackish workaround can be eval-ing the package with the dot notation

e.g.

eval("Packages.org.bukkit."+"event.server"); //or whatever variable it may be

EDIT

The bug has been fixed, so it should work now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top