Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#580 new check: ForbidWildcardAsReturnType

Future
closed
nobody
None
5
2013-11-17
2011-09-23
Roman Ivanov
No

ForbidWildcardAsReturnType.

Joshua Bloch, "Effective Java (2nd edition)" Item 28: page 137 :
"Do not use wildcard types as return
types. Rather than providing additional flexibility for your users, it would force
them to use wildcard types in client code.
Properly used, wildcard types are nearly invisible to users of a class. They
cause methods to accept the parameters they should accept and reject those they
should reject. If the user of a class has to think about wildcard types, there is
probably something wrong with the class’s API."

Options:
- check public method (boolean) (default value = true)
- check protected method (boolean) (default value = true)
- check protected-package methods (boolean) (default value = true)
- check private methods (boolean) (default value = false)
- allow Wildcard with "super" (boolean). example: "? super T" (default value = false)
- allow Wildcard with "extends" (boolean). example: "? extends T" (default value = false)
- ignore list for Class names (regexp), example "Comparable<? super T>". (default value = "Comparable|Comparator")

Discussion

  • Ivan Sopov
    Ivan Sopov
    2013-11-17

    Implemented in sevntu.checkstyle sandbox project.

     
  • Ivan Sopov
    Ivan Sopov
    2013-11-17

    • status: open --> closed
    • Group: --> Future