Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top