coercion from Scala types

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

coercion from Scala types

Ilya Obshadko-2
Just checking - did anyone ever try to create general-purpose type coercer
for Scala types?
It seems to be very natural solution to avoid calling .asJava on every
return type I happen to use from Scala.


--
Ilya Obshadko
Reply | Threaded
Open this post in threaded view
|

Re: coercion from Scala types

Ilya Obshadko-2
Seems the solution is possible, however a little bit tricky: for some
reason you can't import Scala Iterable type into Java code, so everything
has to be done in Scala code instead:

  *def* createTapestryCoercions(configuration:
org.apache.tapestry5.ioc.Configuration[org.apache.tapestry5.ioc.services.CoercionTuple[_,
java.lang.Iterable[_]]]) = {

    *val* coercion = *new* Coercion[Iterable[AnyRef],
java.lang.Iterable[_]] () {

      *def* coerce(arg: Iterable[AnyRef]) = arg.asJava

    }


    configuration.add(*new* CoercionTuple(classOf[Iterable[AnyRef]],
classOf[java.lang.Iterable[_]], coercion))

  }



On Sat, Oct 3, 2015 at 12:17 AM, Ilya Obshadko <[hidden email]>
wrote:

> Just checking - did anyone ever try to create general-purpose type coercer
> for Scala types?
> It seems to be very natural solution to avoid calling .asJava on every
> return type I happen to use from Scala.
>
>
> --
> Ilya Obshadko
>
>


--
Ilya Obshadko