I know how to pass in arguments to a method- you put the class/primitive name in the method header and substitute a value of that type when calling said method. Is it possible to pass in a series of statements to a method (in java), similarly to the way variables are passed in? For example, something such as:
repeat(5) {
System.out.println("Hello");
}
...
private void repeat(int arg, {} statements) {
for (int x = 0; x < arg; x++) {
statements;
}
}
The desired output here would be to print out "Hello" 5 times.
Obviously the syntax isn't correct, but would this be possible in any way?