rspec/rules/S3740/java/rule.adoc

52 lines
963 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Generic types shouldn't be used raw (without type parameters) in variable declarations or return values. Doing so bypasses generic type checking, and defers the catch of unsafe code to runtime.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
List myList; // Noncompliant
Set mySet; // Noncompliant
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
List<String> myList;
Set<? extends Number> mySet;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Provide the parametrised type for this generic.
=== Highlighting
type name
'''
== Comments And Links
(visible only on this page)
=== on 31 Oct 2018, 09:35:37 Nicolas Peru wrote:
\[~alexandre.gigleux] I would suggest title to be reworked to : Don't use raw types. The wording seems dodgy.
=== on 31 Oct 2018, 12:31:09 Ann Campbell wrote:
"Raw types should not be used"?
endif::env-github,rspecator-view[]