Think of a case class like this:
case class User(firstname: String, lastname: String)
now think of calling a method check
with the firstname
check(User.firstname)
The Problem is, that the method check
must have the name of the field too. It must have fieldname and fieldvalue -> "firstname" and "John"
The Question is, is it possible to pass the field of a class instead of its value in the style check(User.firstname)
?
I thought check could look like this (preudocode):
def check(fieldName: String, fieldValue: Any) = {
println(fieldName + ": " + fieldValue)
}
or this
def check(field: Field) = {
println(field.getName)
}
I could pass the fieldname as String by hand but the problem is, the String would not change if I refactor the fieldname and it must match.
Maybe a macro could help? Is there any other solution?