tipsy
01/20/2018, 11:16 AMsay i have a dummy method:
myMethod(Handler handler) { // Handler is a void->void @FunctionalInterface
...
}
in java, i can create non-anonymous handlers in three different ways:
MyClass {
Handler fieldHandler = () -> {};
methodRefHandler(Handler handler) {}
ClassHandler implements Handler {}
}
and call myMethod like this:
myMethod(MyClass.fieldHandler);
myMethod(MyClass::methodRefHandler);
myMethod(new ClassHandler());
what i'm wondering is, what are all the possible ways of calling myMethod (the java version), from kotlinkingsley
01/20/2018, 11:32 AMtipsy
01/20/2018, 11:39 AMkingsley
01/20/2018, 11:41 AMtipsy
01/20/2018, 11:41 AMkingsley
01/20/2018, 11:44 AMnew ClassHandler()
Fields/properties, standalone/within a class, would be the same as your MyClass.fieldHandler
Functions/methods, bound or unbound, will be the same as your MyClass::methodRefHandler
I can’t think of any other different way to achieve this asides what’s already mentionedtipsy
01/20/2018, 11:49 AM