Scala单片眼镜-在E中找不到方法id
类定义如下所示:Scala单片眼镜-在E中找不到方法id,scala,monocle,Scala,Monocle,类定义如下所示: abstract class EntityWithIdHelper[E <: { def id: Int }] { def idLens: Lens[E, Int] = GenLens[E](_.id) ... abstract class EntityWithIdHelper[E您不能为id创建Lens,因为Lens需要一个getter和一个setter,而这里您只有一个getter 另外,如果要使用GenLens[E],E必须是一个case类
abstract class EntityWithIdHelper[E <: { def id: Int }] {
def idLens: Lens[E, Int] = GenLens[E](_.id)
...
abstract class EntityWithIdHelper[E您不能为id
创建Lens
,因为Lens
需要一个getter和一个setter,而这里您只有一个getter
另外,如果要使用GenLens[E]
,E
必须是一个case类