Function.identity returns different type?

Samuel Dennis Borlongan srborlongan at gmail.com
Wed Feb 26 09:58:23 PST 2014


If my experience with mucking around with generics is right, then inlining
asGiven should be coded as :

  static <T> T asIf(T t) {    return Function.<T>identity().apply(t);  }

Since asGiven implicitly "supplies" the type parameter for
Function::identity, while asIf as written does not.

(Help?)

Samuel Dennis R. Borlongan


On Wed, Feb 26, 2014 at 6:14 PM, Timo Kinnunen <timo.kinnunen at gmail.com>wrote:

> Hi,
>
>
>
>
> What's the deal here, how come the "asIf" version - same as "asIn" except
> the method "asGiven" inlined away - doesn't compile?
>
>
>
>
>   static <T> T asIn(T t) {    return asGiven(Function.identity(), t);  }
>
>   static <T> T asIf(T t) {    return Function.identity().apply(t);  }
>
>   static <S, T> T asGiven(Function<S, T> given, S s) {    return
> given.apply(s);  }
>
>
>
>
> The compile error I get is:
>
> error: incompatible types: Object cannot be converted to T
>
>
>
>
> But there's no mention Object in the code...
>
>
>
>
>
> --
> Have a nice day,
> Timo.
>
> Sent from Windows Mail
>
>


More information about the lambda-dev mailing list