Type mismatch: cannot convert from OBSCommandBuilder<capture#2-of ? extends OBSRequest>…
- User
Type mismatch: cannot convert from OBSCommandBuilder<capture#2-of ? extends OBSRequest> to OBSCommandBuilder
private Map<String, OBSCommandBuilder<? extends OBSRequest>> callbacks;
- Assistant
The type mismatch error is occurring because you are trying to assign a value of type
OBSCommandBuilder<? extends OBSRequest>to a variable of typeOBSCommandBuilder<T>whereTis the type parameter of the variable.To fix this, you need to adjust the type of the
callbacksmap to accommodate different type parameter values. One way to achieve this is by using a wildcard for the type parameter of the map.Here's an updated version of the code:
private Map<String, OBSCommandBuilder<?>> callbacks;With this change, you can assign values of any type
OBSCommandBuilderto thecallbacksmap. However, keep in mind that you will lose type safety because the actual type of the value stored in the map won't be known at compile-time. You will have to handle type casting and ensure type safety at runtime.