This is one of those silly thoughts that I can't think of a good reason for doing, but now I'm wondering if one can do it anyway! I checked the JLS, but failed to find anything relevant--that doesn't mean it's not there, of course!
Suppose I have (and bear with the silly example, it's illustrative of the question, not "the problem I need to solve")
Obviously, the simple answer is "don't use the same variable names", and I broadly concur. However, out of interest, Java has some funky syntaxes for this kind of thing (like accessing shadowed members in an enclosing class) , and I'm wondering if there's one for this?
Fair enough, thanks. I suspected this, but realized I'd never actually thought about it before, so wanted to check if I'd missed something. It's hard to distinguish the spec being silent on something from failing to find it.
If you weren't modifying the variable then you could...
I know ;) That's why I made sure to modify the variable, even in the most trivial example.
Actually, that's what led me to wonder. I was using the arguments as initialization values, which was why using the exact same name has "some merit", it's the same situation as would be normal with constructor arguments where you end up with
and I will happily assert that if the two variables actually identify the exact same meaning, then using the same name is reasonable, therefore this can be a good thing(tm). But it's also not a "must have" either.
"Doable", that looks like "Double" but spelled wrong...
Hmm, it does, doesn't it! Glad that didn't get past code review!
yeah, but ... what would PIE do? Especially concerning this tiny ad: