Created
July 13, 2017 00:42
-
-
Save m-doi/b872e281dfbdf042762fb29a54445ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.doilux.generics; | |
import java.util.List; | |
import java.util.function.Function; | |
import java.util.stream.Collectors; | |
public class Odai { | |
public static void printA(List<Int> l) { | |
l.forEach(Int::print); | |
} | |
public static <T extends Printable> void printB(List<T> l) { | |
l.forEach(Printable::print); | |
} | |
public static <T extends HasTwice<T>> List<T> twiceB(List<T> l) { | |
return l.stream() | |
.map(HasTwice::twice) | |
.collect(Collectors.toList()); | |
} | |
public static <T extends HasTwice<T> & Printable<T>> List<T> twiceAndPrint(List<T> l) { | |
return l.stream() | |
.map(HasTwice::twice) | |
.peek(v -> v.print()) | |
.collect(Collectors.toList()); | |
} | |
public static <T extends HasTwice<T> & Printable<T>, R extends HasTwice<T> & Printable<T>> List<R> | |
applyAndPrint(List<T> l, Function<HasTwice<?>, R> g) { | |
return l.stream() | |
.map(g) | |
.peek(v -> v.print()) | |
.collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment