evant / gradle-retrolambda

A gradle plugin for getting java lambda support in java 6, 7 and android
Apache License 2.0
5.3k stars 449 forks source link

Error with explicit generic casts #215

Open lujop opened 8 years ago

lujop commented 8 years ago

If an explicit generic cast is used it is not caught by retrolambda and generated lambda parameter uses Object instead of type provided by generic.

For example in this valid java code using io.reactivex:rxjava and com.trello:rxlifecycle an explicit cast is needed in obs.

LifecycleProvider lifecycleProvider = null;

Observable<Pair> obs = Observable.just(new Pair(1,2));

obs.<Pair>compose(lifecycleProvider.bindToLifecycle())
    .map(v -> v.first)
    .subscribe(v -> Timber.v("%s",v));

This, to my understand, is valid java code but when compiled with retrolambda doesn't compile because v is an object (as is the casting hasn't been made)

PD: I know that casting can be eliminated by providng a generic qualifier in lifecycleProvider declaration. But in any case I think that is valid Java code that doesn't compile with retrolambda.