Вопрос

The following code fails due to "could not find implicit value for rs":


import scalikejdbc.WrappedResultSet

object DatabaseSupport {
  implicit class WrappedResultSetConverter(columnName: String)(implicit rs: WrappedResultSet) extends AnyRef {
    def stringCol: String = rs.string(columnName)
    def intCol: Int = rs.int(columnName)
  }

  def myTest(rsParam: WrappedResultSet) {
      val a: String = "name".stringCol
      val b: String = WrappedResultSetConverter("name").stringCol
  }
}

I had thought that the rsParam parameter to myTest would be visible to the implicits?

Это было полезно?

Решение

It is not visible because it is explicit, it should be made implicit via the implicit keyword.

On the other hand, implicit parameters can be passed as explicit ones to methods.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top