1

I have the following code

protected <TProperty> TProperty getPropertyFromConfig(SubConfiguration cfg,
        String property, TProperty defaultValue, Class<TProperty> clazz)

Which seems readable, but Sonar warns about generic name:

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'

But the description statement is about using a single letter

Following the established convention of single-letter type parameter names helps users and maintainers

So it allows also a digit:

protected <T1> TProperty getPropertyFromConfig(SubConfiguration cfg,
        String property, T1 defaultValue, Class<T1> clazz)

Should it allows generic type name with digits?

EDIT

The duplicate questions/answers doesn't refer to adding digit to generic name

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Some people like shorter code, i suppose. So Sonar adds in a rule to support this. You can turn off that rule if you don't like it. – Sweeper Jan 29 '19 at 07:25
  • See https://stackoverflow.com/a/2900933/10272286. A single number is probably allowed in the regex for sonarlint because other big libraries have used generics like `` etc with single digit numbers. I will see if I can find something to go into more depth about the numbering – SizableShrimp Jan 29 '19 at 07:26
  • @SizableShrimp my question is more about the added digit – Ori Marko Jan 29 '19 at 07:28
  • @Sweeper my question is more about the added digit rule allows – Ori Marko Jan 29 '19 at 07:31
  • 1
    The third dupe addresses digits. – shmosel Jan 29 '19 at 07:36
  • 1
    [this answer](https://stackoverflow.com/a/33394836/2513200) quotes the [google style guide](https://google.github.io/styleguide/javaguide.html#s5.2.8-type-variable-names), which allows digits: "A single capital letter, optionally followed by a single numeral (such as E, T, X, T2) " – Hulk Jan 29 '19 at 13:12
  • [this answer](https://stackoverflow.com/a/44589464/2513200) quotes the [JLS chapter 6.1. Declarations](https://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.1) itself: "Alternately, it is acceptable to use numeric subscripts (e.g., T1, T2) to distinguish among the different type variables." this statement is still present in [the current version 11](https://docs.oracle.com/javase/specs/jls/se11/html/jls-6.html#jls-6.1) – Hulk Jan 29 '19 at 13:18

0 Answers0