I will make an Interface in a class. This interface should allow me to call medoden in another classe.
Classe with Interface.
Other class: (Where function is implemented)
I have used this procedure in my code but I always get an ERROR at "onRun();". (ERROR: ... on a null object reference). Can someone help me in this regard I am already desperate.
This is only an example code.
What do I have to do or what am I doing wrong.
BR René
Classe with Interface.
Code:
public class GenericClass<T> {
public interface GenericInterface<T> {
T onRun();
}
private GenericInterface<T> l ;
public threadFunc (...) {
T myVar = l.onRun();
}
}
Other class: (Where function is implemented)
Code:
public class OtherClass implements GenericClass.GenericInterface<String>{
@Override
public MyClass onRun() {
return "Hallo";
}
}
This is only an example code.
What do I have to do or what am I doing wrong.
BR René
Zuletzt bearbeitet: