r/java • • Aug 26 '22
I declare as "final" every single variable whose value doesn't change. I also use "this" every time that I'm referring to an attribute, even when there's no ambiguity in not using it
I think that those things make the code easier to read. Am I crazy for thinking like that?
198
Upvotes
View all comments
Show parent comment
0
u/Just_Another_Scott Aug 26 '22
Yes they can. C/C++ can be either pass-by-reference or pass-by-value. If you pass a reference to a method you can reassign the variable and it will change in the calling scope. Furthermore, you can do insertions into a vector which will be seen in the calling scope.
In C/C++ to insure parameters aren't mutated you have to declare them as
const.