PHP introduces a method that allows you to pick out all public values of an instance. Is there any way to do this in Scala? That is to fetch all values of all public fields
Just a note to those who try to improve this by making @duncan 's approach type-stronger:
Instead of returning a Map[String, Any], where the value is typed as Any, you could do following:
def propertiesAsPairs() = {
val fields = (this.getClass.getDeclaredFields())
for ( field <- fields ) yield {
field.setAccessible( true );
( field.getName, field.get( this ) );
}
}