Java Reference
In-Depth Information
18-6. Using Java Classes and Libraries
Problem
You want to call upon Java classes and libraries within your Nashorn solution.
Solution
Create JavaScript objects based on Java classes or libraries using the Java.type()
function. Pass the fully qualified string-based name of the Java class that you want to
utilize to this function and assign it to a variable. The following code represents a Java
object named Employee , which will be utilized via a JavaScript file in this applica-
tion.
package org.java8recipes.chapter18.recipe18_06;
import java.util.Date;
public class Employee {
private int age;
private String first;
private String last;
private String position;
private Date hireDate;
public Employee(){
}
public Employee(String first,
String last,
Date hireDate){
this.first = first;
this.last = last;
this.hireDate = hireDate;
}
/**
Search WWH ::




Custom Search