Skip to content

Files

Latest commit

 

History

History
45 lines (28 loc) · 1.48 KB

GenericWhitespace.md

File metadata and controls

45 lines (28 loc) · 1.48 KB

Pattern: Malformed whitespace around < or >

Issue: -

Description

Checks that the whitespace around the Generic tokens (angle brackets) < and > are correct to the typical convention. The convention is not configurable.

Left angle bracket (<):

  • should be preceded with whitespace only in generic methods definitions.
  • should not be preceded with whitespace when it is precede method name or following type name.
  • should not be followed with whitespace in all cases.

Right angle bracket (>):

  • should not be preceded with whitespace in all cases.
  • should be followed with whitespace in almost all cases, except diamond operators and when preceding method name.

Examples with correct spacing:

public void <K, V extends Number> boolean foo(K, V) {} // Generic methods definitions
class name<T1, T2, ..., Tn> {}            // Generic type definition
OrderedPair<String, Box<Integer>> p;      // Generic type reference
boolean same = Util.<Integer, String>compare(p1, p2);  // Generic preceded method name
Pair<Integer, String> p1 = new Pair<>(1, "apple");     // Diamond operator
List<T> list = ImmutableList.Builder<T>::new;          // Method reference
sort(list, Comparable::<String>compareTo);// Method reference

Examples

To configure the check:

<module name="GenericWhitespace"/>

Further Reading