java - Implicitly convert groovy type to pass to a fixed non-groovy method -
i writing scala application loads groovy "plugin" classes @ runtime. once plugins loaded, standard scala types (like list
, option
) passed them processing.
groovy naturally doesn't have syntactic sugar scala types (particularly function*
family), i'd similar easy syntax. best have right use as
operator coerce groovy closures scala types, e.g:
list<string> list = ... // scala list list.map({ it.touppercase() } function1<string,string>)
it nice not have include as ...
tail every time it's bigger actual closure.
this question suggests changing receiving method not specify parameter type, works when it's groovy method can control. i'm using compiled scala/java classes.
i'm aware there various means implicitly converting things in groovy, there many small isolated groovy scripts being loaded independently. don't know groovy enough understand mechanism best suits architecture loaded plugins implicit conversion minimal ceremony , imports. have 50+ plugins streamlining scala/groovy interop worth me.
this simplified version of how i'm loading groovy scripts (where plugin
1 of types):
// created once val currentclassloader = this.getclass.getclassloader val groovyclassloader = new groovyclassloader(currentclassloader) ... // many plugins created way val pluginfile = new java.io.file("path/to/some/plugin/myplugin.groovy") val plugin: plugin = groovyclassloader.parseclass(pluginfile).asinstanceof[plugin] // use val list = list(1,2,3) val answer = plugin.process(list)
thanks in advance!
-rohan
i checked bytecode of function1 scala produces , interface, far not 1 single abstract method. means useless sam conversion, ie. java 8 not able use lambdas autoconvert that. checked abstractfunction1, , while abstract class, has no abstract method, useless extended sam conversion groovy it.
the solution see write extension module conversion.
edit: maybe scala-java8-compat can help. targets allowing java8 lambdas scala functionn, allow sam conversion open blocks in case of groovy 2.2.0 +
Comments
Post a Comment