Skip to content

Can I use nameOf[T](function) to get the field name #18

@CowSmiles

Description

@CowSmiles

Thanks for your awesome work.

I have a problem using nameof without having an instance of the type.

We can use the following way to get a field name

case class Person(name: String, age: Int)

println(nameOf((_:Person).age)) // age
println(nameOf[Person](_.age)) // age

But if I make (_:Person).age to a parameter, so we only get the parameter name, how can i get the real field name according the function:

val foo = (_:Person).age
println(nameOf(foo)) // foo, but I want age
println(nameOf[Person](foo)) // foo, but I want age

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions