How to make the method have another method?

  • 3
    Let me ask: "Why?" - vp_arth
  • one
    You cannot write a method in a method. You can write two separate methods and call one from the other. - pavlofff
  • one
    @vp_arth this construct is used in other PLs. Actually, the top-starter question is about whether it is in Java. Oh, you can use it, believe me) - Kromster
  • 2
    Why minus it? The normal question ... - Barmaley
  • one
    Identical question on enSo: stackoverflow.com/questions/5388584 - Kromster

1 answer 1

Can:

  • Make an unnamed interface implementation inside the method and use its method.
  • As in the last paragraph, only use for this lambda expression.
  • 2
    It is impossible. And what you write here is a banal method call of another object. And in this case it is better to have your own private method. - Sergey
  • one
    @Sergey, formally - yes. But really, this is exactly what is being asked about :) - Qwertiy
  • 2
    in general, these are all crutches (including the answers to enSO from the commentary on the question). In fact, the language does not provide an opportunity to write a method in a method, and the possibility of this seems unnecessary to me, despite assurances in the comments on the question of the opposite. - pavlofff
  • @pavlofff: If it looks like a method and works like a method, then why is this not a method? :) - VladD
  • one
    @Sergey: If you need the functionality of the nested method, <s> and not checkers, </ s> then you should not care how it is implemented. Whether it bulges or not is a matter of syntax sugar available in the language. (Java is traditionally poor in sugar, the committee even took lambda for a very long time.) - VladD