2 ms·
>1. You could use "reflection" or some dynamic feature to do this, but lose type-safety By using reflection you only lose type-safety for this particular funct
by coldtea 6y ago
>1. You could use "reflection" or some dynamic feature to do this, but lose type-safety
By using reflection you only lose type-safety for this particular function. With a dynamic language, you lose it everywhere.
And it's still an one-liner or close in a language without much ceremony (e.g. not Java 1.5).
Example implementation (pseudo-code):
fun capitalize (o: object) -> [f.toUpper() for f in
reflection.fields(o) if reflection.type(f) == "string"]