Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: "No manifest available for type T"

I am working on a Lift project with mixed Scala and Java code.

On the Java side, I have the following relevant items:

interface IEntity

interface IDAO<T extends IEntity> {
    void persist(T t);
}

On the Scala side, I have the following:

abstract class Binding[T <: IEntity] extends NgModel {
    def unbind: T
}

class BasicService[E <: IEntity](serviceName: String, dataAccessObject: IDAO[E]) {
      def render = renderIfNotAlreadyDefined(
        angular.module("myapp.services")
          .factory(serviceName,
            jsObjFactory()
              .jsonCall("persist", (binding: Binding[E]) => {  //<---COMPILATION ERROR
                  try {
                    dataAccessObject.persist(binding.unbind)
                    Empty
                   } catch {
                   case e: Exception => Failure(e.getMessage)
                   }
              })
          )
     )
}

This code will not compile. I get the following error at the point indicated above:

No Manifest available for Binding[E].

It is not clear at all to me why this occurs, but I am guessing it has something to do with this being a nested method invocation. The code compiles fine if I declare a member function with Binding[E] as a parameter, for example:

def someFunction(binding: Binding[E] = { // same code as above }

Why does this happen, and how can I work around it?

like image 706
csvan Avatar asked Aug 13 '14 12:08

csvan


1 Answers

Turns out this is relatively easily solved by implicitly passing on the manifest for the type in question, either in the constructor or the method itself:

class BasicService[E <: IEntity](serviceName: String, dataAccessObject: IDAO[E])(implicit m: Manifest[Binding[E]]) {

or

def render(implicit m: Manifest[Binding[E]])
like image 159
csvan Avatar answered Sep 19 '22 22:09

csvan