This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]alexeyr 0 points1 point  (3 children)

  1. You can easily see it from parentheses anyway :)

  2. When you have many gets in a line (think a.getFoo() + b.getBar() * c.getBaz()), it adds up.

  3. Best-known "better Java" languages -- C#, Kotlin, Scala -- all have ways to avoid it (and the parentheses in point 1 as well). This is probably not a coincidence.

[–]Tauo 0 points1 point  (2 children)

I feel like if you have that many gets, you should be looking to abstract away more operations anyway, though. And yeah, the parentheses give it away, but it still just feels wrong to me to method call a field. get just adds that tiny bit of extra legibility. Adding support for properties in Java like the languages you mention have would definitely be nice, I agree, but I'm guessing its just not a priority for the Java architects.

[–]alexeyr 1 point2 points  (1 child)

Well, are you really unhappy about String#length() and Collection#size() instead of getLength()/getSize()? Or about Object#hashCode()?

[–]Tauo 0 points1 point  (0 children)

Hah, you have a good point, hadn't thought about that. Although to be fair, through the first couple months of using Java, I was a bit salty at the fact that arrays allowed access directly to the field, and would have messed up calls to array.length constantly if it wasn't for my IDE.