Are Java 8 lambdas compiled as inner classes, methods or something else? [duplicate]

The expression itself, assuming you pass an actual lambda expression and not a method reference, is compiled as a separate, synthetic method. In addition to any formal arguments to the expected functional interface (e.g., a single String in the case of Consumer<String>), it will include arguments for any captured values. At the code location where … Read more

Visualization of Java Stream parallelization

Current Stream API implementation uses collector combiner to combine the intermediate results in exactly the same way as they were previously split. Also the splitting strategy depends on the source and common pool parallelism level, but does not depend on exact reduction operation used (the same for reduce, collect, forEach, count, etc.). Relying on this … Read more

Spring + AspectJ weaving for java 8 using aspectj-maven-plugin

Solution before the official release prior to Sep 2015 After many headaches and many hours struggling against this, fortunately I could solve this problem. Here is what I did: To use aspectj-maven-plugin with Java 8 I could configure version aspectj-maven-plugin 1.7 (Note that aspectj-maven-plugin 1.6 works for Java 7). So, the maven plugin configuration needs … Read more

Nested Java 8 parallel forEach loop perform poor. Is this behavior expected?

The problem is that the rather limited parallelism you have configured is eaten up by the outer stream processing: if you say that you want eight threads and process a stream of more than eight items with parallel() it will create eight worker threads and let them process items. Then within your consumer you are … Read more

Does collect operation on Stream close the stream and underlying resources?

There is a trick to make the Stream implementation calling close() after the terminal operation: List<String> rows = Stream.of(Files.lines(inputFilePath)).flatMap(s->s) .collect(Collectors.toList()); It simply creates a stream encapsulating the stream of lines as a single item and uses flatMap with an identity function (Function.identity() would work as well) to turn it into a stream of lines again. … Read more

Android N Java8 java.time

java.time package was added only in API 26 (Android O): https://developer.android.com/reference/java/time/package-summary.html UPDATE Starting with version 4.0 of the Android Gradle Plugin, you can use a subset of java.time APIs (along with a number of other Java 8 language APIs) without requiring a minimum API level for your app: https://developer.android.com/studio/write/java8-support#library-desugaring The following set of APIs are … Read more