Java claims to be object oriented and typesafe, and Scala even more so.
Internal Class fields are represented by class called Field, which you can obtain a reference to via the Reflection API.
My question: do these languages provide any way to obtain that Field reference in a typesafe way? (And if not, why on earth not? Seems like a glaring deficiency)
It would be extremely useful when mapping an Object to some external representation, for example to html fields in a template, or to column names in a database, to keep the reference names automatically in sync.
Ideally I'd like to say something like:
My question: do these languages provide any way to obtain that Field reference in a typesafe way?
Compile-time typesafe? Not that I'm aware of, at least in Java. The normal purpose of reflection in Java is for code to be able to deal with types it has no knowledge of before-hand - it's rare (in my experience) to be in a position where you want to be able to refer to a field in a known type. It does happen, but it's not very common.
(And if not, why on earth not? Seems like a glaring deficiency)
Every feature needs to be designed, implemented, tested, and has to meet the balance of providing more value than the added complexity in the language.
Personally I can think of features I'd much rather see in Java than this.