加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – “No Manifest available for Type”错误

发布时间:2020-12-16 18:21:12 所属栏目:安全 来源:网络整理
导读:我尝试编写一些 Scala类 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
我尝试编写一些 Scala类

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)

但我得到了:

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]() })}}
                                                                                      ^

据我所知,我需要为lambda函数设置隐式Manifest参数

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

但是我该怎么做呢?或者我完全错了?

解决方法

你只需要从顶部传递清单,其中类型是已知的:

class Xyz[T : Manifest] { ...

应该这样做.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读