- Loading...
...
Anchor explicit_overload_resolution explicit_overload_resolution
Explicit method signatureselection
When you call java method from script, Nashorn automatically selects the most specific overload variant of that method (based on the runtime type of the actual arguments passed – with appropriate type conversions as needed). But sometimes you may want to manually select a specific overload variant. If so, you can specify method signature along with the method name.
...
| Code Block | ||
|---|---|---|
| ||
var out = java.lang.System.out; out["println(int)"](Math.PI); // selects PrintStream.println(int). // prints 3 as Math.PI is converted to int |
Explicit constructor selection (jdk9)
With jdk9, explicit constructor overload selection is also supported. See Index selection of overloaded java new constructors and Explicit constructor overload selection should work with StaticClass as well
| Code Block | ||
|---|---|---|
| ||
// With jdk9, you can select a specific constructor as well.
var C = java.awt["Color(int,int,int)"];
print(new C(255, 0, 0);
var F = Java.type("java.io.File")["(String)"];
print(new F("foo.txt"));
|
...