Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CowSmiles opened this issue Jul 7, 2021 · 1 comment
Open

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

CowSmiles opened this issue Jul 7, 2021 · 1 comment

Comments

@CowSmiles
Copy link

CowSmiles commented Jul 7, 2021

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

@CowSmiles CowSmiles changed the title can i using nameOf[T](function) Can I use nameOf[T](function) to get the field name Jul 8, 2021
@plmuninn
Copy link

I can say I have same issue - I'm trying to pass expr: T => Any into nameOf[T] and what I'm getting is name of parameter passed to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants