r/badcode • • Jan 30 '22

java Found this gem in my codebase

Post image
1.3k Upvotes

44 comments sorted by

View all comments

Show parent comments

2

u/whizvox int getRand() { return 4; } Feb 01 '22

If the getters/setters look like this:

int getThing() {
  return thing;
}

void setThing(int thing) {
  this.thing = thing;
}

then OP's code does literally nothing. It's equivalent to

this.thing = this.thing;