For parameter types, favor interfaces over classes 

es.uniovi.reflection.analyses.bloch.7.40.2


This rule detects parameters whose type implements an interface that can be safely used to type the parameter instead. This means that all the methods invoked by and attributes accessed on the parameter must belong to the interface type (or the Object class). If the parameter is passed as argument to some method, this method must accept the interface type as argument too. If the parameter is iterated in a for-each loop, the interface type must extend the java.lang.Iterable interface. Additionally, if the parameter is assigned to some variable, it will be checked that the type of this variable canbe safely changed to the interface type too. Also, if the parameter belongs to a method that overrides or is overridden by another method, it will not be considered. Parameters whose type is an enum or already an interface are not considered. Finally, too general interfaces such as java.io.Serializable, java.lang.Comparable, java.lang.Cloneable, java.lang.constant.Constable, java.lang.constant.ConstantDesc and java.lang.CharSequence are not recommended for the change.

Computational Reflection Research Group
09-30-2026 22:23
Bad Practice
Parameter Declaration