Effective Java⢠(Jason Arnold's Library) by Joshua Bloch
Author:Joshua Bloch
Language: eng
Format: epub
Publisher: Addison-Wesely
Published: 2008-02-15T00:00:00+00:00
public enum BasicOperation implements Operation {
PLUS("+") {
public double apply(double x, double y) { return x + y; }
},
MINUS("-") {
public double apply(double x, double y) { return x - y; }
},
TIMES("*") {
public double apply(double x, double y) { return x * y; }
},
DIVIDE("/") {
public double apply(double x, double y) { return x / y; }
};
private final String symbol;
BasicOperation(String symbol) {
this.symbol = symbol;
}
@Override public String toString() {
return symbol;
}
}
While the enum type (BasicOperation) is not extensible, the interface type (Operation) is, and it is the interface type that is used to represent operations in APIs. You can define another enum type that implements this interface and use instances of this new type in place of the base type. For example, suppose you want to define an extension to the operation type above, consisting of the exponentiation and remainder operations. All you have to do is write an enum type that implements the Operation interface:
// Emulated extension enum
public enum ExtendedOperation implements Operation {
EXP("^") {
public double apply(double x, double y) {
return Math.pow(x, y);
}
},
REMAINDER("%") {
public double apply(double x, double y) {
return x % y;
}
};
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7427)
Robo-Advisor with Python by Aki Ranin(7310)
Offensive Shellcode from Scratch by Rishalin Pillay(5946)
Ego Is the Enemy by Ryan Holiday(4891)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(4701)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4414)
Python for ArcGIS Pro by Silas Toms Bill Parker(4021)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3728)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3439)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3260)
Speed Up Your Python with Rust by Maxwell Flitton(3215)
Liar's Poker by Michael Lewis(3192)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3180)
Extreme DAX by Michiel Rozema & Henk Vlootman(3155)
Agile Security Operations by Hinne Hettema(3107)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3097)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3070)
Cryptography Algorithms by Massimo Bertaccini(2986)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2969)
