Created
February 6, 2017 08:23
-
-
Save PaulWoitaschek/4ac68aaa08d53f7e87d3379054a231f4 to your computer and use it in GitHub Desktop.
Kotlin interop failue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////// java base class | |
public final class GenericInterop { | |
public interface BaseChanger<From, To> { | |
Base<To> change(Base<From> from); | |
} | |
public static class Base<T> { | |
public final <R> Base<R> compose(BaseChanger<? super T, ? extends R> changer) { | |
//noinspection unchecked | |
BaseChanger<T, R> casted = (BaseChanger<T, R>) changer; | |
return casted.change(this); | |
} | |
} | |
} | |
///////////// java knows type diamonds: | |
public GenericInterop.Base<String> transform(GenericInterop.Base<Integer> intBase) { | |
return intBase.compose(from -> new GenericInterop.Base<>()); | |
} | |
/////////// kotlin doesnt know type, need to specify <String> | |
fun transform(intBase: GenericInterop.Base<Int>): GenericInterop.Base<String> { | |
return intBase.compose { GenericInterop.Base<String>() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment