method inner class


I have a method say

public class Test{
public void processPay(@suspended AsyncResponse response, final Checklist checks){

new thread() {
public void run(){


why we need final access variable as highlighted above. when we need to pass access modifier within method argument which i never remember doing it.

Please advise
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I do it all the time. I tend to make my method arguments final so I don't accidentally change them.
Good practice.
gudii9Author Commented:
I do it all the time. I tend to make my method arguments final so I don't accidentally change them.

do we need to do it in the method calling place or in the method implementation place as above?

i mean
ObjectA a= new ObjectA();
a.doSomething(int a, int b);//method calling place

inside ObjectA class we have
public class ObjectA{

public void doSomething(a, b){// the method implementation place

please advise
in your words....
the method implementation place
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

one does not "need" to do it.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Getting back to the original question, the time that you DO "need" the final modifier is in the case that you were eluding to, where if you are defining an anonymous inner class within the method (such as the Thread subclass in your example) and from within that inner class, you want to be able to access any variables defined outside it, the compiler requires those variables to have been defined final.

The reason is that the code defined within the inner class may be executed at any/various points in time, it doesn't necessarily just run straight away, and so the point at which it does run, the original method may have already finished and it's method arguments are out of scope. So defining them as final tells the compiler that YOU as the developer know that the values in those variables will never change, and so it allows the compiler to then take a copy of them for use inside the inner class code.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
However in your case you are not making use of the checks argument at all.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.