getting an "receiver type mismatch" error while tr...
# announcements
n
getting an "receiver type mismatch" error while trying to avoid code duplication. I had
fun <T> Connection.use(block : (Connection) -> T) : T = try { return block(this) } finally { this.close() }
and same function for
PreparedStatement
and
ResultSet
. This all works, but I wanted to replace the three with a single
fun <U : Closeable, T> U.use(block : (U) -> T) : T = try { return block(this) } finally { this.close() }
. Now code like
connection.use { c-> ...}
no longer compiles and says: "Cannot infer a type for this parameter"