Say i have the following class:
class Person {
@BeanProperty
var firstName: String = _
}
Is it possible to get the String representation of "firstName" in a type-safe way, by reflection or something? Or the String representation of the generated "getFirstName"-Function?
It would be nice if it would somehow look like:
val p = new Person
p.getFunction(p.getFirstName).toString // "getFirstName"
p.getAttribute(p.firstName).toString // "firstName"
EDIT
Ok, more explanation is needed ;)
Say i want to build a SQL query like this:
val jpql = "select p from Person p where p.age > 20";
So i want to make it as typesafe as possible and write something like this:
val jpql = "select p from " + classOf[Person].getName + " where p." +
Person.getAttName(p.age) + " > 20";
In this way, if it's possible to refactor Scala code in the future, i could change the attribute name of Person without breaking my code.