Skip to main content
Commonmark migration
Source Link

Two advantages that I see are listed :

#1 Marking the method argument as final prevents reassignment of the argument inside the method

1 Marking the method argument as final prevents reassignment of the argument inside the method

From you example

 public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){ // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument fTz = Calendar.getInstance().getTimeZone(); return .. } 

In a complicated method marking the arguments as final will help in accidental interpretation of these arguments as methods local variables and reassigning as compiler will flag these cases as shown in the example.

#2 Passing the argument to an anonymous inner class

2 Passing the argument to an anonymous inner class

As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final.

Two advantages that I see are listed :

#1 Marking the method argument as final prevents reassignment of the argument inside the method

From you example

 public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){ // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument fTz = Calendar.getInstance().getTimeZone(); return .. } 

In a complicated method marking the arguments as final will help in accidental interpretation of these arguments as methods local variables and reassigning as compiler will flag these cases as shown in the example.

#2 Passing the argument to an anonymous inner class

As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final.

Two advantages that I see are listed :

1 Marking the method argument as final prevents reassignment of the argument inside the method

From you example

 public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){ // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument fTz = Calendar.getInstance().getTimeZone(); return .. } 

In a complicated method marking the arguments as final will help in accidental interpretation of these arguments as methods local variables and reassigning as compiler will flag these cases as shown in the example.

2 Passing the argument to an anonymous inner class

As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final.

Two advantages that I see are listed :

#1 Marking the method argument as final prevents reassignment of the argument inside the method

From you example

public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){

fTz = Calendar.getInstance().getTimeZone(); // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument

return ..

}

 public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){ // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument fTz = Calendar.getInstance().getTimeZone(); return .. } 

In a complicated method marking the arguments as final will help in accidental interpretation of these arguments as methods local variables and reassigning as compiler will flag these cases as shown in the example.

#2 Passing the argument to an anonymous inner class

As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final.

Two advantages that I see are listed :

#1 Marking the method argument as final prevents reassignment of the argument inside the method

From you example

public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){

fTz = Calendar.getInstance().getTimeZone(); // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument

return ..

}

In a complicated method marking the arguments as final will help in accidental interpretation of these arguments as methods local variables and reassigning as compiler will flag these cases as shown in the example.

#2 Passing the argument to an anonymous inner class

As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final.

Two advantages that I see are listed :

#1 Marking the method argument as final prevents reassignment of the argument inside the method

From you example

 public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){ // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument fTz = Calendar.getInstance().getTimeZone(); return .. } 

In a complicated method marking the arguments as final will help in accidental interpretation of these arguments as methods local variables and reassigning as compiler will flag these cases as shown in the example.

#2 Passing the argument to an anonymous inner class

As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final.

Source Link

Two advantages that I see are listed :

#1 Marking the method argument as final prevents reassignment of the argument inside the method

From you example

public String changeTimezone(final Timestamp stamp, final Timezone fTz, final Timezone toTz){

fTz = Calendar.getInstance().getTimeZone(); // THIS WILL CAUSE COMPILATION ERROR as fTz is marked as final argument

return ..

}

In a complicated method marking the arguments as final will help in accidental interpretation of these arguments as methods local variables and reassigning as compiler will flag these cases as shown in the example.

#2 Passing the argument to an anonymous inner class

As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final.