7

Java rant...

If public field declaration is so so bad, why can't all class fields in java just be private by default? And make it a pain in the ass to expose it as public?

I can't actually remember a time declared a class field as public, it is muscle memory now... Private bla Bla Bla, return, private bla Bla, return...

Comments
  • 1
    At a guess, I'd say it's still that way for backwards compatibility 😊
  • 0
    Visibility in another class I think, if everything was private people get errors they didn't understand why.
  • 1
    Java 9 should just do what Scala does: automatically add getters and setters to public fields
  • 0
    I'm sure there is / was a legitimate reason, but I just think for the sanity of the future, for a language that claims is OO it should be able to enforce certain good practices as implied and and make it possible to do otherwise with some little extra work.

    I agree, for backward compatibility that's probably impossible to change now.
Add Comment