Answer the question
In order to leave comments, you need to log in
How is passing a function to a Java object implemented?
An object of a simple class is created:
At the same level, there is a methodMediaProfiler profiler = new MediaProfiler();
void f() {
Log.e("TAG", "d");
}
void f() {
Log.e("TAG", "d");
}
private void spot() {
profiler = new MediaProfiler();
profiler.onRun=f; //но не работает
}
public class MediaProfiler {
public MediaProfiler() {
//...
}
public void onRun() {
//изменится после изменения
}
}
Answer the question
In order to leave comments, you need to log in
class SomeClass {
void f() {
Log.e("TAG", "d");
}
private void spot() {
profiler = new MediaProfiler();
profiler.onRun(SomeClass::f);
}
}
public class MediaProfiler {
public void onRun(Runnable f) {
f.run()
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question