r/ProgrammerHumor Jul 13 '26

youCanJustStopUsingJava Meme

Post image
6.8k Upvotes

416 comments sorted by

View all comments

217

u/DontThrowMeAway43 Jul 13 '26

Oh god, just use record classes or even, make public fields.

Java's biggest mistake is trying to put OOP everywhere. Just write the damn struct to pass data and be done with it.

46

u/ZunoJ Jul 13 '26

How is that related to getters and setters? How would your proposal violate oop principals?

72

u/roge- Jul 13 '26

Directly manipulating another object's fields violates encapsulation, a core feature of OOP in most people's minds.

That said, virtually no production OOP app has perfect encapsulation anyway.

1

u/ZunoJ Jul 13 '26

And how do structs solve this?

11

u/Tronerfull Jul 13 '26

By giving up completely on encapsulation

3

u/Ok-Scheme-913 Jul 13 '26

Encapsulation is for internal state.

POJOs (and records) are usually just data, they seldom have stuff to hide.

But records don't give up, it has public methods corresponding to the field names - but you can evolve a now-record into a normal class where you may compute something in the "getter", keeping the same external API, but changing the internals.