Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No Manifest available for Type" error

Tags:

scala

I try to write some Scala classes

abstract class A { var a : Int = _}
class B[T] extends A { var b : T = _ }
class C[T] extends A { var c : T = _ }
class Abc[T : Manifest] {
    var array : Array[T] = _
    def this(capacity : Int, f : Unit => T) = {
        this()
        array = new Array[T](capacity)
        for(i <- 0 until capacity)
            array(i) = f()
    }
}

class Xyz[T] { 
    var m : Abc[C[T]] = _; 
    def this(capacity : Int) = { 
    this(); 
    m = new Abc[C[T]](capacity, Unit => { new C[T]() })
    }
}

var xyz = new Xyz[Int](10)

But I got:

error: No Manifest available for C[T].
       class Xyz[T] { var m : Abc[C[T]] = _; def this(capacity : Int) = { this(); m = new Abc[C[T]](capacity, Unit => { new C[T]() })}}
                                                                                      ^

As far as I understand I need to set up implicit Manifest argument for the lambda function

Unit => { new C[T]() })

But how can I do that? Or I am completly wrong?

like image 746
user1312837 Avatar asked May 25 '16 18:05

user1312837


1 Answers

You just need to carry the manifest all the way from the top, where the type is known:

class Xyz[T : Manifest] { ...

should do it.

like image 116
Dima Avatar answered Nov 17 '22 19:11

Dima