1

I have the following code:

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

def extractFieldNames[A](implicit m: Manifest[A]): Array[String] =
    m.runtimeClass.getDeclaredFields.map(_.getName)

extractFieldNames[Person]
// should return Array("name", "age")

But what if I want to exclude age because of its default parameter? How would I do this?

user3685285
  • 6,066
  • 13
  • 54
  • 95
  • This might not be possible... seems that default parameters are completely handled at compile time, and at runtime all of that information is gone, at least as far as I can tell. For instance, if you call `.getConstructors` you'll only see a two-argument version, even though you can call it as if it had one argument. – Joe K Jul 25 '18 at 20:08
  • check [this](https://stackoverflow.com/questions/13812172/how-can-i-create-an-instance-of-a-case-class-with-constructor-arguments-with-no) may help – proximator Jul 28 '18 at 21:18

0 Answers0