Skip to content
Advertisement

Tag: java-8

Possibility to explicit remove Serialization support for a lambda

As already known it’s easy to add Serialization support to a lambda expression when the target interface does not already inherit Serializable, just like (TargetInterface&Serializable)()->{/*code*/}. What I ask for, is a way to do the opposite, explicitly remove Serialization support when the target interface does inherit Serializable. Since you can’t remove an interface from a type a language-based solution would

Accumulator Generator test – Java 8

Paul Graham, in his great article Revenge of the Nerds, claimed that languages vary in power. He mentioned a nice exercise – writing an accumulator generator: We want to write a function that generates accumulators– a function that takes a number n, and returns a function that takes another number i and returns n incremented by i. Solution in Java

Why is “final” not allowed in Java 8 interface methods?

One of the most useful features of Java 8 are the new default methods on interfaces. There are essentially two reasons (there may be others) why they have been introduced: Providing actual default implementations. Example: Iterator.remove() Allowing for JDK API evolution. Example: Iterable.forEach() From an API designer’s perspective, I would have liked to be able to use other modifiers on

Iterate an Enumeration in Java 8

Is it possible to iterate an Enumeration by using Lambda Expression? What will be the Lambda representation of the following code snippet: I didn’t find any stream within it. Answer In case you don’t like the fact that Collections.list(Enumeration) copies the entire contents into a (temporary) list before the iteration starts, you can help yourself out with a simple utility

Merge lists with stream API

I have the following situation I have to merge all the lists lst from the ListContainer objects from a Map map. Any idea how, using Java 8 stream API? Answer I think flatMap() is what you’re looking for. For example:

Advertisement