Java 8 - Under the Hood

Click here to load reader

  • date post

  • Category


  • view

  • download


Embed Size (px)


Presentation about upcoming features of Java 8 mainly with regard to functional programming (lambdas). The presentation compares the features with Scala. It was presented by Vlastimil Menčík at the May's Czech Scala Enthusiasts meetup held at Faculty of Information Technology in Prague.

Transcript of Java 8 - Under the Hood

  • 1.Java 8: Under the HoodVlastimil Menk

2. - syntaxx => x + 1_ + 1Integer.parseInt Integer::parseIntx -> x + 1MyClass MyClass::newif MyClass is a case class 3. - types functional interfacesaka SAM interfaces target typing applicable to legacyinterfaces FunctionN String => Int Currying PartialFunction 4. Functional Interface 5. Interoperability with Scala 6. - implementation in Scala instances of FunctionX traits compiled into anonymous inner classesMyClass$$anonfun$1.class a lot of extra bytecode 7. - implementation in Java 8 implementation in synthetic methods invokedynamic LambdaMetafactory 8. in bytecode 9. invokedynamic since Java 7 java.lang.invoke what really gets invoked is resolved at runtimeby delegating to a bootstrap method 10. LambdaMetafactory contains bootstrap methods for converting -expressions to functional interface objects 11. invokedynamic + LambdaMetafactoryinvokedynamic #2 12. x -> x + 5 13. When will this be in Scala? after Scala moves away from Java 6 2.11 will have experimental Java 7 backend 2.12 will target Java 8 14. Java 8: Stream API 15. Parallel streams very similar to parallel collections in Scalastream.parallel()stream.sequential()col.parcol.seq 16. More lambdas in Java API java.util.function standard functional interfaces Function, BiFunction, Predicate, Supplier, java.util.Optionalpublic T orElseGet(Supplier