Is it safe for me to write a Java program with imports like this:
You are supposed to use them through
javax.script as explained on https://docs.oracle.com/javase/8/docs/jdk/api/nashorn/jdk/nashorn/api/scripting/package-summary.html
Package jdk.nashorn.api.scripting Description
This package provides the
javax.scriptintegration, which is the preferred way to use Nashorn. You will ordinarily do this to obtain an instance of a Nashorn script engine:
import javax.script.*; ... ScriptEngine nashornEngine = new ScriptEngineManager().getEngineByName("Nashorn");
But to answer your question, i would say "Probably not". The only officially guaranteed supported packages are
Any new unsupported packages would not be named
sun.* since Oracle now owns Java.
It's likely that someone picked
jdk.* as a new unsupported package prefix since
sun.* is no longer available.
The other potential problem is that your program won't run on another JDK that does not include Nashorn.