Created
December 20, 2012 21:37
-
-
Save trecloux/4348782 to your computer and use it in GitHub Desktop.
Java 8 lambda type inference question
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 org.junit.Test; | |
import java.util.ArrayList; | |
import java.util.List; | |
import static java.util.Arrays.asList; | |
import static org.fest.assertions.Assertions.assertThat; | |
public class LambdaSample { | |
private final List<String> names = asList("John", "Shaun", "Jeremy", "Richard", "Thomas"); | |
@Test | |
public void shouldFilter() throws Exception { | |
List<String> filtered = names.stream() | |
.filter(x -> x.startsWith("J")) | |
.into(new ArrayList<>()); // -> Does not compile, needs explicit typing : .into(new ArrayList<String>()); | |
assertThat(filtered).containsOnly("John", "Jeremy"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment