4 ms·
He means how in Java you can do something like this: class Foo { private Integer bar = 0; public Integer baz() { Integer inc =
by lilactown 10y ago
He means how in Java you can do something like this:
class Foo {
private Integer bar = 0;
public Integer baz() {
Integer inc = 2;
bar += inc;
return bar;
}
}
Where `bar` is referred to in the same way a local variable is, even though it's actually a property of the class the method is defined on. It's equivalent to using `this.bar` but the compiler accepts it anyway.
- pvg 10y agoRight, the confusing thing was talking about 'class methods'.
- hnbroseph 10y agothe confusing thing was pointlessly wasting time on things that weren't confusing.
- xxs 10y agoplease don't use java.lang.Integer unless you really have to. I know it's just an example but it gives the wrong ideas of what good code is. Each operation in baz() consists of Integer.intValue() and Integer.valueOf(int), like Integer inc = Integer.valueOf(2); bar = Integer.valueOf(bar.intValue() + inc.intValue()) ... besides dealing with unneeded indirection values outside [-128 : 127] actually create an object that has to be allocated+GC'd each assignment. Such nuances give Java the bad rap. 'int' maps straight to the hardware, java.lang.Integer - not so much.
- hnbroseph 10y agothis seems like a rather odd tangent.
- xxs 10y agoyou mean the syntactic sugar or the jab at java.lang.Integer? Flip note, the code would fail w/ NullPointerException if bar was not initiated (bar=0) but left null.
- _jal 10y agoThe jab at j.l.Integer. I have my pet annoyances, too, don't get me wrong. Just the other day, I saw someone in a coffee shop using 8-stop tabs and had to set them straight. They were in the middle of a conversation about food, but this is important.