This post was brought to you by this PMD rule.

Transcription

Why do we have this stupid code analyzer rule enabled anyway? Nobody writes code like this…

After telling them the lore why it’s there:

You have seen such things before?

11 Times, as a matter of fact

  • Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    4 days ago

    Well, I think your idea would be simpler, if we weren’t talking about Java.
    Pretty much everything is an object in Java. It’s only logical that a type would also be an object and have associated fields.

    Similarly, what you’re thinking of as “reference types directly” doesn’t make sense in Java, because it lacks many of the systems to make that actually usable like a type. What you get from .class is a Class object, which you can’t stick into a generic type parameter, for example.
    It basically uses reflection to give you e.g. the name of that type and you can also instantiate an object of that type, if no parameters need to be passed to the constructor function.

    And then, yeah, I think for explaining that you merely get an object which roughly describes the type, the separate .class field is a good idea.