import scala.util.control.NonFatal
class Base(a: Int)(initBlock: Base => Unit) {
try (initBlock(this))
catch {
case NonFatal(ex) => // ...
}
def doSomething(): Unit = println("do something")
}
object MyApp extends App {
Base(1) { base =>
base.doSomething()
}
}
I want the initBlock
can access the doSomething
even if it’s private
, any hint? thanks.