Java Reference
In-Depth Information
QUICK SUMMARY
1. The AggressiveOpts flag enables certain optimizations in base classes. For the
most part, these classes are faster than their replacements, but they may have un-
expected side effects.
2. These classes have been removed in Java 8.
Lambdas and Anonymous Classes
For many developers, the most exciting feature of Java 8 is the addition of lambdas. There is
no denying that lambdas have a hugely positive impact on the productivity of Java deve-
lopers, though of course that benefit is difficult to quantify. But we can examine the perform-
ance of code using lambda constructs.
The most basic question about the performance of lambdas is how they compare to their re-
placement, anonymous classes. There turns out to be little difference.
The usual example of how to use a lambda class begins with code that creates anonymous in-
ner classes (the usual example often uses a Stream rather than the iterator shown here; in-
formation about the Stream class comes later in this section):
private
private volatile
volatile int
int sum ;
public
public interface
interface IntegerInterface
IntegerInterface {
int
int getInt ();
}
public
public void
void calc () {
IntegerInterface a1 = new
new IntegerInterface () {
public
public int
int getInt () {
return
return 1 ;
}
};
IntegerInterface a2 = new
new IntegerInterface () {
public
public int
int getInt () {
return
return 2 ;
}
};
IntegerInterface a3 = new
new IntegerInterface () {
Search WWH ::




Custom Search