This is a pleasant change. A discussion about Java and not
TheNewLanguageOfTheWeek.
I'm a pretty lightweight programmer compared with you guys, so I tried
the following snippet of code to see what effect the final keyword
would have..
public static void main(String[] args)
{
Person p = new Person(); // A simple class with a single
property.
p.setName("Andrew");
System.out.println(p.getName());
updatePerson(p);
System.out.println(p.getName());
}
private static void updatePerson(final Person p)
{
p.setName("Billy");
}
Output:
Andrew
Billy
My simple (perhaps even simplistic) conclusion is that the final
keyword has not added any protection but has added the false
appearance of protection. All that has happened is that the dangers
of getting things wrong through not using final have been swapped for
different dangers of getting things wrong when using final.
Personally, I'd be inclined to use Occam's razor and keep things
simple by not adding keyword that are only partially effective, stick
with the common idiom and rely on tests, not coding style, to prove
the code.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---