Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How to put methods as Java parameters?
Hi I was curious on how to put methods on Java parameter. I need to make a method which will loop methods (that I put into the program) the number of times I want
Here's what I got:
private void doStuff(int a)
{
// does actions based on "a"
}
private void looper (int times, /*how to show specific method*/)
{
for (int k = 0; k < times; k++)
methodFromParameter(a);
}
I tired stack overflow, but no responses... any help would be appreciated... thanks...
1 Answer
- deonejuanLv 77 years agoFavorite Answer
New in Java 8 is Lambda expressions. It's all new and I'm having great fun trying to wrap my head around it. Lambda expressions are anonymous functions. Like EddieJ said there are ways to do it without Lambda, but less elegant, in fact from what you show would take two classes and an interface.