Inspectopedia
 
2024.3

Type may be weakened

Warning
New
Last modified: 03 December 2024

Reports variable and method return types that can be changed to a more abstract (weaker) type. This allows making the code more abstract, hence more reusable.

Example:

Enable the Only weaken to an interface checkbox below to only report a problem when the type can be weakened to an interface type.

Enable the Do not suggest weakening variable declared as 'var' checkbox below to prevent reporting on local variables declared using the 'var' keyword (Java 10+)

Stop classes are intended to prevent weakening to classes lower than stop classes, even if it is possible. In some cases, this may improve readability.