Answer the question
In order to leave comments, you need to log in
How to correctly specify the type of the callback argument without casting?
Let's say there is a callback
private void callback (Map<String, Color> data) {
Color color = data.get("color");
}
new RenderThreadsController<>(this::callback);
@FunctionalInterface
public interface Callback <T> {
void callback (Map<String, T> data);
}
Map<String, T> data = new HashMap<>();
data.put(
"color",
(T) new Color(
random.nextInt(255),
random.nextInt(255),
random.nextInt(255)
)
);
this.callback.callback(data);
(T) new Color(
random.nextInt(255),
random.nextInt(255),
random.nextInt(255)
)
Answer the question
In order to leave comments, you need to log in
Map<String, T> data = new HashMap<>();
data.put(
"color",
(T) new Color(
random.nextInt(255),
random.nextInt(255),
random.nextInt(255)
)
);
this.callback.callback(data);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question