Woe is me for using ? super T in a method call (part 2)

Timo Kinnunen timo.kinnunen at gmail.com
Sun Mar 2 09:27:57 PST 2014


Hi, 


Picking up from part 1, here’s the other, related example:


public class RegressionsMaybe {

  static <T extends A_SUPER_T, A_SUPER_T> 

  void typeParametersMadeRelatedForDemoPurposes() {

    BinaryOperator<Consumer<? super T>> op1_1 = Consumer::andThen;//not error?

    BinaryOperator<Consumer<A_SUPER_T>> op2_1 = Consumer::andThen;//ok

  

    BinaryOperator<Consumer<? super T>> op1_2 = RegressionsMaybe::andThen1;//error?

    BinaryOperator<Consumer<A_SUPER_T>> op2_2 = RegressionsMaybe::andThen1;//ok..

  

    BinaryOperator<Consumer<? super T>> op1_3 = RegressionsMaybe::andThen2;//error?

    BinaryOperator<Consumer<A_SUPER_T>> op2_3 = RegressionsMaybe::andThen2;//ok..

  }

  private static <T> 

  Consumer<T> andThen1(Consumer<T> before, Consumer<? super T> after) {

    return (T t) ->   { before.accept(t); after.accept(t); }; }

  private static <T extends SUPER_T, SUPER_T> 

  Consumer<T> andThen2(Consumer<T> before, Consumer<SUPER_T> after) { 

    return (T t) -> { before.accept(t); after.accept(t); }; }

}





In the above, ECJ shows 3 errors but javac only shows 2. Before I report the op1_1 line not compiling in ECJ as a bug I’d like to understand why it shouldn’t be an error. Also why the other ones are or are not errors. Yes, I’d really like to understand all of it.





-- 
Have a nice day,
Timo.

Sent from Windows Mail


More information about the lambda-dev mailing list