|
Sorry if this is really basic, it's been about 3-4 years since I've done any real Java and I don't know how to Google this because that's exactly what it's about : this. When is it appropriate and when is it inappropriate to reference a variable/function/anything as this.exampleThing instead of just exampleThing? No need to re-invent the wheel, if someone could point me at the correct search term I'd really appreciate it. So far, I've just found "it's a style thing" which is kind of insane. Why put "this" in front of every god drat thing if it's not needed? Edit: stackoverflow posted:You only need to use this - and most people only use it - when there's an overlapping local variable with the same name. (Setter methods, for example.) Really? Really? gotly fucked around with this message at 04:00 on Sep 3, 2011 |
# ¿ Sep 3, 2011 03:58 |
|
|
# ¿ May 29, 2024 18:31 |
|
carry on then posted:Yeah, the only time I've ever seen it is when a parameter and an instance variable have the same name, or an instance variable and a local variable. (edit: I guess a parameter is just a local variable, isn't it?) Just to make sure I have it 100% - in this case, MyClass will actually change BUTTS and leave CHEWBACCA alone?
|
# ¿ Sep 3, 2011 04:30 |
|
Thanks guys, cleared it up a lot. I program in something drastically different during the day so it's always nice to see what seasoned Java guys consider best practice. Also, if I could write production code like baquerd I'd die a happy man.
|
# ¿ Sep 3, 2011 05:31 |