case class Person(name: String)
def getMethodName(....): String = {
// ....
}
getMethodName(Person::name) // returns "name" or "Person.name"
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class Person {
def firstname() = {
"Scala"
}
}
val f: (Person, Person) => Int = _ firstname _
val g = (_: Person) firstname (_: Person)
Error:(9, 23) too many arguments for method firstname: ()String
val g = (_: Person) firstname (_: Person)
^
Error:(8, 38) too many arguments for method firstname: ()String
val f: (Person, Person) => Int = _ firstname _
^
class Person {
def age() = {
Random.nextInt
}
}
def getMethodName(property: Person => Int): String = {
// How to reflect the property name itself out of the anonymous function
}
val property: Person => Int = (_: Person).age
println(getMethodName(property)) // should print "Person.age"