venerdì 27 marzo 2015

Fork Join to transform list of objects - java 8

Following the previous post, here you are a little update if you're using java 8. The interface TransformFunction can be transformed into a functional interface.

@FunctionalInterface
public interface TransformFunction<T, S> {

        T transform (S source);

}

Doing this, you can trigger the process that converts a list of Integer into a list of String object typing something like this:

ListTransformer<String, Integer> transformer = new ListTransformer<>(sources, source -> Integer.toString(source));
List<String> result = transformer.compute();

You can notice how it all becomes more simple.

Hope it can help!




Nessun commento:

Posta un commento