Concerning the type handling in all apply methods below.
Concerning the type handling in all apply methods below.
Unfortunately the obvious approach (as follows) doesn't work as expected in all scenarios :
def apply[T1](f: (T1) => Any)(implicit m1:Manifest[T1]) = { register(List(m1)) { case List(a1:T1) => f(a1) } }
This is due to the Scala 'Value Classes' being boxed when moving into the Java world, and then returned into the Scala layer as these boxed types, which causes the following use case.
- Step definition is defined with expected argument of scala type 'Int' - Step is 'registered' passing the Scala Int type into the Java layer - Inside the Java layer this is boxed from a 'primitive' into a java.lang.Integer - The parsed value is returned into Scala layer, retaining it's boxed type - When we perform the pattern match in the partial function, a List[Int] is expected but List[java.lang.Integer] is passed in and fails the match (causing a match exception)
Therefore by casting we unbox the java.util.Integer (or other boxed type) back into the expected value working around this issue - anything else should be the expected object anyway, so it makes no difference in that case.
There's likely a cleaner way of doing this - please refactor if so.