Feature Sets and Examples
By: Justin Dragos
@EllisandePoet
New date/time APIs live in the java.time package
Java 8 introduces local times that don't hold a UTC offset. Since they don't hold a UTC offset these cannot be converted into seconds since the epoch (java.util.Date)
Offsets and instants are much closer foundationally to java.util.Date as they all represent an absolute point in time.
We also now have a concept of spans of time. This can be represented in two ways:
Clock marchFifth = Clock.fixed(Instant.now(), ZoneId.of("America/Phoenix"));
TimeTest.java
Multiple Inheritance finally comes to java! Interfaces can now have default implementations of their methods. This allows you to:
Since collections no longer has to worry about breaking all Java code ever written, they enhanced the APIs!
Ball
int bounceHeight(int)
BeachBall
int bounceHeight(int)
HardBall
int bounceHeight(int)
LeadBeachBall
bounceHeight?
DefaultMethodImplementationTest.java
Car.java
New.java
News.java
Old.java
Volume.java
AnnotationTest.java
Closures come to Java! … Mostly.
A lambda expression is an anonymous method implementation for a functional interface.
So… that’s weird for Java, what do those things mean?
A functional interface is an interface that has one and only one method without a default implementation (i.e. one truly abstract method)
@FunctionalInterface
public interface Filterable<T> {
void filter(T item);
}
@FunctionalInterface
public interface Filterable<T> {
void filter(T item);
default T filter(T item){
filter(item);
return item;
}
}
Alright, lets break it down:
(sayWhat) -> { System.out.println("I said "+ sayWhat); }
(sayWhat) : names the input params for the lambda expression
-> : separates the parameter declaration from the method body
{ ... } : the body of the lambda expression
Thanks for attending!
Have any questions or comments?
If you are interested in opportunities with State Farm, or just want to know more about us, please stop by our booth in the cafeteria or talk to me after the presentation.
Github: http://github.com/Ellisande/java-8-examples
Twitter: @EllisandePoet