Created
May 11, 2017 05:48
-
-
Save mashiro/ce70c5371028baea279047966c15320e to your computer and use it in GitHub Desktop.
Extension Method
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
import lombok.experimental.ExtensionMethod; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Stream; | |
import java.util.stream.Collectors; | |
@ExtensionMethod({StreamExtensions.class}) | |
public class Main { | |
public static void main(String[] args) { | |
List<Integer> a = (new Integer[] {1, 2, 3}).stream().map(v -> v * 2).toList(); | |
System.out.println(a); | |
} | |
} | |
class StreamExtensions { | |
public static <T> Stream<T> stream(T[] array) { | |
return Arrays.stream(array); | |
} | |
public static <T> List<T> toList(Stream<T> stream) { | |
return stream.collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment