java - Why some programmers like to add final keyword in the method params? -


recently,i found in projects add final keyword in method parameters like:

public static string getsuffix(final string filename) {     if (filename.indexof('.') >= 0) {         return filename.substring(filename.lastindexof('.'));     }     return emtpy_string; } public httpresult(final int statuscode) {     this.statuscode = statuscode; } 

it can catch bugs.

for example, if write :

public httpresult(final int statuscode) {     statuscode = statuscode; } 

you compilation error, since assigning value local final variable, while if write

public httpresult(int statuscode) {     statuscode = statuscode; } 

you won't compilation error, statuscode member won't assigned.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -