Can use bounded wildcard
Reports generic method parameters that can make use of bounded wildcards.
Example:
should be replaced with:
This method signature is more flexible because it accepts more types: not only Consumer<Number>, but also Consumer<Object>.
Likewise, type parameters in covariant position:
should be replaced with:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
BoundedWildcard- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
To quote Joshua Bloch in Effective Java third Edition:
Use the inspection options to toggle the reporting for:
invariant classes. An example of an invariant class is
java.util.List<T>because it both accepts values (via theList.add(T)method) and produces values (via theT List.get()method).On the other hand,
contravariantclasses only receive values, for example,java.util.function.Consumer<T>with the only methodaccept(T). Similarly,covariantclasses only produce values, for example,java.util.function.Supplier<T>with the only methodT get().People often use bounded wildcards in covariant/contravariant classes but avoid wildcards in invariant classes, for example,
void process(List<? extends T> l). Disable this option to ignore such invariant classes and leave them rigidly typed, for example, .void process(List<T> l)privatemethods, which can be considered as not a part of the public APIinstance methods
Inspection options
Here you can find the description of settings available for the Can use bounded wildcard inspection, and the reference of their default values.
- Report invariant classes
Default value:
Selected- Report private methods
Default value:
Selected- Report instance methods
Default value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |