This has nothing to do with reflection, but you can pass "method references" if you are using java 8+. Assuming from your example that you intend to use methods that take no parameters and just return an int, you could do this:
public class MyClass {
public int getIntMemberFunction(){ ... }
public static int getIntStaticFunction(){ ... }
}
with your update function modified to look like this,
public boolean update(IntSupplier s){ //input is a method reference or lambda
int i = s.get();
// logic relating to the value of i
}
Then you could call update
passing in a reference to any static function on any class as long as it takes no parameters and returns an int, like this:
boolean result = update(MyClass::getIntStaticFunction);
or you could call update
passing in a reference to any member function of a specific object as long as it takes no parameters and returns an int, like this:
MyClass myClassInstance = ...
boolean result = update(myClassInstance::getIntMemberFunction);
If you want to add methods that take 1 or 2 parameters, you could create versions of update
that take ToIntFunction
or ToIntBiFunction
. Beyond 2 parameters you would have to add your own functional interfaces.