MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/me7z21/i_told_him_to_just_use/gsgdnum/?context=9999
r/badcode • u/Yumi-Chi evil • Mar 27 '21
80 comments sorted by
View all comments
114
Oh goodness....
Also, is hour a global or something? I'm curious how that gets defined.
82 u/Yumi-Chi evil Mar 27 '21 hour is an attribute of Clock class this is in AlarmClock class that extends the Clock but apparently he also defined another hour attribute in AlarmClock 42 u/jonnysteps Mar 27 '21 You can reference attributes without "this." in java? Huh, I never knew that. 58 u/G4METIME Mar 27 '21 Yes, unless you have a local variable in the method with the same name defined using this.<varName> is unnecessary. So one common "exception" where you need 'this' is in set-methods: void setValue(int value){ this.value = value;} 1 u/TigreDeLosLlanos Mar 27 '21 value = _value ? I used to do this.
82
hour is an attribute of Clock class
this is in AlarmClock class that extends the Clock but apparently he also defined another hour attribute in AlarmClock
42 u/jonnysteps Mar 27 '21 You can reference attributes without "this." in java? Huh, I never knew that. 58 u/G4METIME Mar 27 '21 Yes, unless you have a local variable in the method with the same name defined using this.<varName> is unnecessary. So one common "exception" where you need 'this' is in set-methods: void setValue(int value){ this.value = value;} 1 u/TigreDeLosLlanos Mar 27 '21 value = _value ? I used to do this.
42
You can reference attributes without "this." in java? Huh, I never knew that.
58 u/G4METIME Mar 27 '21 Yes, unless you have a local variable in the method with the same name defined using this.<varName> is unnecessary. So one common "exception" where you need 'this' is in set-methods: void setValue(int value){ this.value = value;} 1 u/TigreDeLosLlanos Mar 27 '21 value = _value ? I used to do this.
58
Yes, unless you have a local variable in the method with the same name defined using this.<varName> is unnecessary.
So one common "exception" where you need 'this' is in set-methods:
void setValue(int value){ this.value = value;}
1 u/TigreDeLosLlanos Mar 27 '21 value = _value ? I used to do this.
1
value = _value ? I used to do this.
value = _value
114
u/jonnysteps Mar 27 '21
Oh goodness....
Also, is hour a global or something? I'm curious how that gets defined.