#2507 Field.hasDefault()

SlimerDude Sat 6 Feb 2016

When using reflection to inspect method parameters, there's a useful Param.hasDefault() method:

Void foo(Str bar := "wotever") { ... }

#foo.params.first.hasDefault()  // --> true

I was wondering if it's possible to have similar for fields?

Str? foo
Str? bar := "wotever"

#foo.hasDefault()  // --> false
#foo.hasDefault()  // --> true

brian Sat 6 Feb 2016

was wondering if it's possible to have similar for fields?

Probably not because that is an entirely different thing from how the compiler works and what is considered public in a class. Method parameters are something a caller needs to know. How fields get initialized is very much an implementation detail since it all really just happens in the constructor (field initializers just get inserted into the construction process)

Login or Signup to reply.