File: ClassNamedLikeTypeParameter.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (30 lines) | stat: -rw-r--r-- 817 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
In the [Google Style Guide][gsg], 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:

```java
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.

[gsg]: https://google.github.io/styleguide/javaguide.html#s5.2.8-type-variable-names