I quite often see the following naming convention used in java code.
class SomeClass {
private final String name;
public SomeClass(final String name) {
this.name = name;
}
}
This seems a little odd to me. First off if you happen to misspell the variable in the method signature it will still compile...
class SomeClass {
private final String name;
public SomeClass(final String nane) {
this.name = name;
}
}
Compiles fine. Possibly flags nane as unused variable but the assignment (which just becomes a self assignment) silently compiles.
I find myself wanting to use 'm' for member variables as such...
class SomeClass {
private final String mName;
public SomeClass(final String name) {
mName = name;
}
}
It is shorter than the .this variant and catches the odd misspelling error shown previously.
However a colleague of mine gave me all kinds of flack when I brought this up as a convention on our new project stating that "in java we don't do that.".
Just curious as to why?