In the Google Style Guide, type parameters are named in one of two patterns:
- A single capital letter, optionally followed by a single numeral (such as E, T, X, T2)
- A name in the form used for classes…, followed by the capital letter T (examples: RequestT, FooBarT).
If a regular class is named like this, then it might be confusing for users of your API:
class Bar {
...
public void doSomething(T object) {
// Here, object is the static class T in this file
}
public <T> void doSomethingElse(T object) {
// Here, object is a generic T
}
...
public static class T {...}
}
Looking at T
, it’s very likely to be confused as a type parameter instead of a
class.
Suppress false positives by adding the suppression annotation @SuppressWarnings("ClassNamedLikeTypeParameter")
to the enclosing element.