当前位置: 动力学知识库 > 问答 > 编程问答 >

Scala Monocle - Cannot find method id in E

问题描述:

The class definition looks like this:

abstract class EntityWithIdHelper[E <: { def id: Int }] {

def idLens: Lens[E, Int] = GenLens[E](_.id)

...

How do you avoid this problem - Cannot find method id in E? Is there any workaround?

网友答案:

You cannot create a Lens for id because a Lens requires a getter and a setter and here you only have a getter.

Also if you want to use GenLens[E], E has to be a case class.

分享给朋友:
您可能感兴趣的文章:
随机阅读: