You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] Enhance UseExplicitTypes to allow verbose long explicit types #6903
I'd basically like a rule that flags usage of the var keyword when the (normally) written type would be below a certain length.
Writing var x = 0 instead of int x = 0 makes not a lot of sense and just makes reading/reviewing the code (without an IDE) harder.
Also most IDEs have a "variable extraction feature" that automatically adds the correct type.
Using var for something like Iterator<? extends Map.Entry<? extends MySuperCoolCacheKey, ? extends MySuperCoolValue>> however is a lot reasonable IMHO.
// Could have just used an `int`// Will create an `int` however you might want a `byte` or `short`varx = 0;
// DANGEROUS: infers as List<Object>varlist = List.of();
// What is customers? Maybe a List? a Set?varcustomers = dbconn.executeQuery("SELECT ...");
// A dozen lines of other code go here...customers.map(...).toList(); // Nevermind it was a Stream...
Describe the solution you'd like
Enhance the existing rule UseExplicitTypes
add a property to allow types with a given minimum length, e.g. lengthLimit - The rule will be triggered when the length of the type is below this limit
Describe alternatives you've considered
a new rule
Additional context
Add any other context about the feature request here.
changed the title [-][java] New rule: AvoidVarForShortType[/-][+][java] Enhance UseExplicitTypes to allow verbose long explicit types[/+]on Oct 3, 2026
Activity
AB-xdev commentedon Jul 22, 2026
As I already did a reference implementation I will send a PR for this
UncleOwen commentedon Jul 22, 2026
Maybe find a better example here. The list returned by
List.of()is empty and immutable, so this is safe.But I like the idea, awaiting your PR!
[-][java] New rule: AvoidVarForShortType[/-][+][java] Enhance UseExplicitTypes to allow verbose long explicit types[/+][doc] Update release notes (pmd#6903)
[java] Fix pmd#6903: Rewrite UseExplicitTypes as Java rule to support…