type equality constraint: accept unbounded/extends wildcards pair; reject unbounded/super

This commit is contained in:
Anna Kozlova
2014-01-31 14:26:50 +04:00
parent 2070864b80
commit 4444fc1126
3 changed files with 94 additions and 13 deletions

View File

@@ -0,0 +1,37 @@
public class SampleExtendsWildcard {
public void highlightsTheBug(Stream<String> stream) {
stream.flatMap((Block<?> sink, String element) -> {});
}
public interface Block<B> {
void apply(B t);
}
public interface Stream<S> {
<R> Stream<R> flatMap(FlatMapper<? super S, R> mapper);
}
public interface FlatMapper<F, R> {
void flatMapInto(Block<? extends R> sink, F element);
}
}
class SampleSuperWildcard {
public void highlightsTheBug(Stream<String> stream) {
stream.flatMap((<error descr="Incompatible parameter types in lambda expression">Block<?> sink</error>, String element) -> {});
}
public interface Block<B> {
void apply(B t);
}
public interface Stream<S> {
<R> Stream<R> flatMap(FlatMapper<? super S, R> mapper);
}
public interface FlatMapper<F, R> {
void flatMapInto(Block<? super R> sink, F element);
}
}