0

I found a method similar to the following:

private void methodA(String firstArg, String secondArg) {
    final String queueFirstArg = firstArg;
    final String queueSecondArg = secondArg;
    executor.execute(new Runnable() {
        public void run() {
           methodB(queueFirstArg, queueSecondArg);
        }
    }
}

It looks like bad code and making both arguments 'final' would be enough. Am I missing something? Is there any benefit in using that approach?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • What problems come from bad coding style? I don't know what kind of answer you want to get here. The code you posted it not good, like the other people already said. So i think the question is answered now – Stimpson Cat Oct 24 '18 at 12:17

1 Answers1

0

Yes, it's "bad code" because of redundant local variables, because you can add final to arguments without afraid to change caller behavior, see answer:

Java always makes a copy of parameters before sending them to methods. This means the final doesn't mean any difference for the calling code.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233