# HG changeset patch # User chegar # Date 1519302233 0 # Node ID 9efadce38a17f169592e871ccde7b386d978cc2a # Parent f1b75e394b6883856dfc836046b2385b1664013f http-client-branch: more compile-only type param in generic method tests diff -r f1b75e394b68 -r 9efadce38a17 test/jdk/java/net/httpclient/FlowAdaptersCompileOnly.java --- a/test/jdk/java/net/httpclient/FlowAdaptersCompileOnly.java Tue Feb 20 15:23:54 2018 +0000 +++ b/test/jdk/java/net/httpclient/FlowAdaptersCompileOnly.java Thu Feb 22 12:23:53 2018 +0000 @@ -21,6 +21,9 @@ * questions. */ +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.util.Collection; @@ -145,4 +148,56 @@ BodySubscriber bs12 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f3); BodySubscriber bs13 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f4); } + + // --- + + static class NumberSubscriber implements Flow.Subscriber> { + @Override public void onSubscribe(Flow.Subscription subscription) { } + @Override public void onNext(List item) { } + @Override public void onError(Throwable throwable) { } + @Override public void onComplete() { } + public Number getNumber() { return null; } + } + + static class IntegerSubscriber extends NumberSubscriber { + @Override public void onSubscribe(Flow.Subscription subscription) { } + @Override public void onNext(List item) { } + @Override public void onError(Throwable throwable) { } + @Override public void onComplete() { } + public Integer getInteger() { return null; } + } + + static class LongSubscriber extends NumberSubscriber { + @Override public void onSubscribe(Flow.Subscription subscription) { } + @Override public void onNext(List item) { } + @Override public void onError(Throwable throwable) { } + @Override public void onComplete() { } + public Long getLong() { return null; } + } + + static final Function numMapper = sub -> sub.getNumber(); + static final Function intMapper = sub -> sub.getInteger(); + static final Function longMapper = sub -> sub.getLong(); + + public void makesSureDifferentGenericSubscriberSignaturesCompile() + throws Exception + { + HttpClient client = null; + HttpRequest request = null; + IntegerSubscriber sub1 = new IntegerSubscriber(); + + HttpResponse r1 = client.send(request, BodyHandler.fromSubscriber(sub1, IntegerSubscriber::getInteger)); + HttpResponse r2 = client.send(request, BodyHandler.fromSubscriber(sub1, IntegerSubscriber::getInteger)); + HttpResponse r3 = client.send(request, BodyHandler.fromSubscriber(sub1, NumberSubscriber::getNumber)); + HttpResponse r4 = client.send(request, BodyHandler.fromSubscriber(sub1, intMapper)); + HttpResponse r5 = client.send(request, BodyHandler.fromSubscriber(sub1, intMapper)); + HttpResponse r6 = client.send(request, BodyHandler.fromSubscriber(sub1, numMapper)); + + // compiles but makes little sense. Just what you get with any usage of `? super` + final Function objectMapper = sub -> 1; + client.sendAsync(request, BodyHandler.fromSubscriber(sub1, objectMapper)); + + // does not compile, as expected ( uncomment to see ) + //HttpResponse r7 = client.send(request, BodyHandler.fromSubscriber(sub1, longMapper)); + } }