Java Reference
In-Depth Information
be extended, along with a JavaScript object containing the implementations that will be
altered.
The following code is that of the Employee class, which will later be extended
from within a JavaScript file.
package org.java8recipes.chapter18.recipe18_09;
import java.math.BigDecimal;
import java.util.Date;
public class Employee {
private int age;
private String first;
private String last;
private String position;
private Date hireDate;
. . .
public BigDecimal grossPay(BigDecimal hours,
BigDecimal rate){
return hours.multiply(rate);
}
}
Here's the JavaScript code used to extend the class and use it:
var Employee
= Java.type("org.java8recipes.chapter18.recipe18_09.Employee");
var bigDecimal = Java.type("java.math.BigDecimal");
var Developer = Java.extend(Employee, {
grossPay: function(hours, rate){
var bonus = 500;
return hours.multiply(rate).add(new
bigDecimal(bonus));
}
});
var javaDev = new Developer();
Search WWH ::




Custom Search