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类