0

Possible Duplicate:
Why should I use the keyword “final” on a method parameter in Java?

What's the point of the final keyword in Java? If I pass a non-final int to a method and change it inside of the method, it's still the same as it was before the method was invoked after the method is invoked. If I pass a final object to a method and change the object's attributes while inside of the method, the attributes have still be changed after the method was invoked.

So, why have the final keyword at all, in the method's signature? If you change the argument's value while inside the method, they're still going to remain the same outside of the method, and if you change an object's attributes then that object's state has changed - regardless of whether or not it's final. So, what's the purpose? What advantage does this method provide?

Community
  • 1
  • 1
user919860
  • 3,083
  • 4
  • 19
  • 16
  • 2
    There's so many question already on SO about it. – Nettogrof Nov 07 '11 at 20:59
  • you are confusing the **reference** with the Object. `final` makes the **reference** immutable, not the state of the Object itself. –  Nov 07 '11 at 21:03
  • Isn't the reference the same thing? When given a parameter in Java, you're pretty much given a copy of the value. Objects, however, are still changed from within a method if change their values, because the object's name is a copy of the reference. If, you reassign that object inside of your method to a different object, the object will still remain the same outside of the invoked method. All that you did was make that variable reference some other object in some different place in memory. The original reference remains untouched. – user919860 Nov 08 '11 at 20:14

0 Answers0