i very seriously doubt that this style of writing would slow your code down at all - it seems to me like something the compiler should be able to very easily identify and optimize for. but even if it does, i'd still do it; you gain so much more clarity about what kind of variable you're using, your code gets so much more easily readable, that i think it would be worth it.
It's exactly the same thing. In this case the "this" reference is implied. Even if there were a difference, in any non-trivial program the difference certainly would be dwarfed by GUI code, IO overhead, network latency and so on.
The choice of variable names does not affect execution times. The choice of method names might do this if it results in dynamic dispatching (polymorphism), but variable references are resolved at compile time.
[ February 25, 2005: Message edited by: Mike Gershman ] [ February 25, 2005: Message edited by: Mike Gershman ]
Originally posted by Jeff Bosch: If you're hiding a variable name, which you're doing here by using the same name in the parameter list as in the class, you need to use this to remove ambiguity.
For example, the following code prints correctly:
The output is "Testing 1-2-3", as expected. However, if we remove the "this" keyword, as in the following code:
The output here is "null". Why? Because Java tried to assign "this.title" to "this.title" because it didn't know which "title" the assignment wanted to use for the right value!
By the way, the original code also had two capitalization errors, "Public" for "public" and "Class" for "class". Java cares about such things.
Actually, the parameter named "title" overrides the member variable named "title". So in the later example, "title=title" assigns the value of the parameter to itself. However, when the method returns, the memory where the parameter is stored is destroyed, so the assignment essentially did nothing.