Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Java Method Reference (pass method as parameter)

I want to pass method as a parameter in a method like

callMethod(someArg, methodToPass)

And in the definition of callMethod, I want to call this fn ie. MethodToPass i.e in another java file and the arguments for fn MethodToPass are being initialized in this callMethod only.

Please tell me how can I do that??

Answer*

Draft saved
Draft discarded
Cancel
3
  • My signature of "methodToPass" has return type void and it accepts 5 arguments of different types and I want to pass only its reference in "callMethod" and its arguments i'm calculating inside callMethod definition and after that I want to call this method that I passed as a Parameter with the arguments I calculated in "callMethod" fn Commented Oct 10, 2018 at 7:51
  • Ok, I'll try this solution. I'm able to understand it and will update you about it. Thanku😃 Commented Oct 10, 2018 at 8:11
  • Useful to add that SomeClass can also be an instance if you want to call a non-static method and it can also be this if you want to reference the current instance. Commented Oct 10, 2018 at 8:16

lang-java

AltStyle によって変換されたページ (->オリジナル) /