I am trying to override a method of trait in my case class which want to display all the members of case class. I am using it for debugging purpose.
trait A{
def myMethod(employee:Emp):Unit
}
case class Emp(id:String,name:String) extends A {
override def myMethod(employee: Emp): Unit =
emp.productIterator.toList.foreach(println)
}
other possible way to do this is
emp.productIterator.toList.mkString("\n")
to declare Emp("10","abc")
. I am new to Scala
, not sure how to call the override method of trait
.
I am not sure if any other generic way to achieve this functionality to get string form of case class members.
Efficient way to use trait and case class to achieve this functionality.I want to understand how apply method and companion objects can be implemented .
- I want to implement
logging
instead of usingprintln
. Can anyone suggest a tutorial for it?
Previous answer was because i didn't understood your question right. This should answer your question:
If you want this only for debugging purposes you can use it like that:
But more logical would be to use object with this nonGeneric method:
For logging purposes you can use just apache log4j