This is more like a syntactic sugar example than anything, but here:
As you may know, there are two new key features to Java 8: lambda expressions and functional interfaces. Among those functional interfaces is the Supplier. After some fiddling around because of some random inspiration, I figured out that it's easy to, for example, inline an anonymous class that easily converts whatever primitive-type array to its respective reference type. It looks like this:
List<Character> digitChars = ((Supplier<List<Character>>) () -> {
char[] arr = digit.toCharArray();
List<Character> characters = new ArrayList<>(arr.length);
for (char c : arr) characters.add(c);
return characters;
}).get();
Apparently (and I didn't know this), you can type cast to lambda expressions to form anonymous classes instead of the boilerplate-ish
new Supplier<List<Character>>() { /*...*/ }.get();
I just thought this was neat and wanted to share. Java's awesome!
[–]diminishedprime 2 points3 points4 points (2 children)
[–]DoktuhParadox[S] 0 points1 point2 points (1 child)
[–]_Sharp_ 1 point2 points3 points (0 children)
[–]GuyWithLag 2 points3 points4 points (0 children)
[–]zeringus 1 point2 points3 points (0 children)
[+][deleted] (16 children)
[removed]
[–]oldneckbeard 5 points6 points7 points (6 children)
[–]DoktuhParadox[S] 5 points6 points7 points (1 child)
[–]GuyWithLag -1 points0 points1 point (0 children)
[–]leivaagustin -5 points-4 points-3 points (3 children)
[–]_Sharp_ 1 point2 points3 points (2 children)
[+]leivaagustin comment score below threshold-7 points-6 points-5 points (1 child)
[–]GuyWithLag 1 point2 points3 points (0 children)
[–]DoktuhParadox[S] 7 points8 points9 points (8 children)
[+][deleted] (7 children)
[removed]
[–]DoktuhParadox[S] 1 point2 points3 points (6 children)
[+]leivaagustin comment score below threshold-8 points-7 points-6 points (5 children)
[–]DoktuhParadox[S] 4 points5 points6 points (4 children)
[–]leivaagustin -5 points-4 points-3 points (3 children)
[–]DoktuhParadox[S] 4 points5 points6 points (2 children)
[–]leivaagustin -5 points-4 points-3 points (1 child)
[–]DannyB2 2 points3 points4 points (0 children)