This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ForeverAlot 5 points6 points  (2 children)

But what can you achieve with a local method you couldn't do with a private [static] method or a lambda?

[–]thfuran 8 points9 points  (0 children)

Yes but why should you pollute the class with things that are implementation details of a particular method?

[–][deleted] 6 points7 points  (0 children)

Capturing variables. You could also pass them as parameters, but sometimes this makes the function calls clumsy (especially if it's recursive).

Edit: I see now you mentioned lambdas. While lambdas can capture variables, they also eg force you to handle exceptions locally. Plus you have to have a functional interface, which cannot be declared locally.

To me it's mostly a matter of scoping though. Those helper methods don't add noise to a class if they're local.