I have a trait and trying to implement it in Main object. Is this possible and what is the best practice?
trait PrintThis {
def nowPrint (thing:String)
}
object Main extends PrintThis {
def main(args: Array[String]): Unit = {
def nowPrint(thing:String): Unit = {
println("subject" )
}
nowPrint("test")
}
}
If that is not possible - is this a better approach (extend trait in another class and implement trait method inside another class and then extend that class in Main class and call the method)?
trait One {
def show()
}
class Two extends One {
def show() {println ("This is a show!") }
}
object Main extends Two {
def main(args: Array[String]): Unit = {
show()
}
}
Or maybe is better instantiating that new class inside Main and not extending it?
object Main {
def main(args: Array[String]): Unit = {
var pointer:Two = new Two
pointer.show()
}
}