| 1 |
// Test case for issue #979: |
| 2 |
// https://github.com/typetools/checker-framework/issues/979 |
| 3 |
|
| 4 |
// @skip-test until the bug is fixed |
| 5 |
|
| 6 |
import java.util.List; |
| 7 |
import java.util.stream.Collectors; |
| 8 |
import java.util.stream.Stream; |
| 9 |
import org.checkerframework.checker.nullness.qual.Nullable; |
| 10 |
|
| 11 |
public class CollectorsToList { |
| 12 |
|
| 13 |
void m(List<String> strings) { |
| 14 |
Stream<String> s = strings.stream(); |
| 15 |
|
| 16 |
// This works: |
| 17 |
List<String> collectedStrings1 = s.collect(Collectors.<String>toList()); |
| 18 |
// This works: |
| 19 |
List<@Nullable String> collectedStrings2 = s.collect(Collectors.toList()); |
| 20 |
// This works: |
| 21 |
@SuppressWarnings("nullness") |
| 22 |
List<String> collectedStrings3 = s.collect(Collectors.toList()); |
| 23 |
|
| 24 |
// This assignment issues a warning due to incompatible types: |
| 25 |
List<String> collectedStrings = s.collect(Collectors.toList()); |
| 26 |
|
| 27 |
collectedStrings.forEach(System.out::println); |
| 28 |
} |
| 29 |
} |