I'll make the Listener
itself generic:
public interface Listener<T> {
void onReady(T t);
}
And then the convert
method should also be generic:
public <T> void convert(String string, Class<T> resultClass, Listener<T> listener) {
try {
listener.onReady(resultClass.newInstance());
} catch (IllegalAccessException e) {
} catch (InstantiationException e) {
}
}
And call it like:
convert("Test", MyClass.class, new Listener<MyClass>() {
@Override
public void onReady(MyClass object) {
}
});