[java] S1188 should differentiate between Lambdas and anonymous classes

The rule S1188 has only one setting for the maximum allowed lines of a lambda or an anonymous class, hence treats both constructs the same. But I don’t think they should be treated the same.
When passing a lambda to a method, I’m implementing a functional interface with a single method; further the lambda should be as short as possible, ideally a method reference.
When creating an anonymous class I can override multiple methods, sometimes I have to (e.g. implementing a MouseListener or extending a MouseAdapter). Anonymous classes should be short, too, but there is more overhead (override annotations, method signatures,…).
Therefore, the rule should allow different settings for lambdas and anonymous classes.

push

1 Like

Hey @oliver, @Holger_Mensch and voters,

Thanks for the feedback. I share the feeling that we should not address both Lambdas and Anonymous classes with the same rule. Especially since you may want to have different threshold. Consequently, I split the rule in two, S1188 will continue addressing Anonymous classes, but ONLY anonymous classes, while a new rule, S5612 will target explicitly, and only, lambdas.

Here are the tickets related to the split and implementation of the rule:

Cheers,
Michael

1 Like