How do you declare a variable that can be assigned with such method:
def inTransaction[A](a: =>A): A =
if(! Session.hasCurrentSession)
_executeTransactionWithin(SessionFactory.newSession, a _)
else {
a
}
Thanks in advance, Etam.
As paradigmatic said, you need to assign a type. But as a workaround, you can use an object.
object myFunc {
def apply[A](a: =>A): A = ???
}
You cannot directly assign a method to a variable, it must be transformed in a closure object (Function*). This transformation may happen implicitly or manually by adding an _ after the function name.
Since a variable cannot be generic, you must fix the type during assignation. For instance:
scala> def size[A]( lst: List[A] ) = lst.size
size: [A](lst: List[A])Int
scala> var f = size[Int] _
f: List[Int] => Int = <function1>