-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathGenerics_Common.inc.qhelp
More file actions
56 lines (47 loc) · 1.62 KB
/
Generics_Common.inc.qhelp
File metadata and controls
56 lines (47 loc) · 1.62 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
The use of generics in Java improves compile-time type safety and
code readability.
Users of a class or interface that has been designed using generic types
should therefore make use of parameterized instances
in variable declarations, method return types, and constructor calls.
</p>
</overview>
<recommendation>
<p>
Provide type parameters to generic classes and interfaces where possible.
</p>
<p>
Note that converting legacy code to use generics may
have to be done carefully in order to preserve the existing
functionality of an API; for detailed guidance, see the references.
</p>
</recommendation>
<example>
<p>The following example is poorly written because it uses raw types. This makes it
more error prone because the compiler is less able to perform type checks.</p>
<sample src="Generics_Common.java" />
<p>A parameterized version can be easily made and is much safer.</p>
<sample src="Generics_CommonGood.java" />
</example>
<references>
<li>
J. Bloch, <em>Effective Java (second edition)</em>,
Item 23.
Addison-Wesley, 2008.
</li>
<li>
Help - Eclipse Platform:
<a href="https://help.eclipse.org/2020-12/advanced/content.jsp?topic=/org.eclipse.jdt.doc.user/reference/preferences/java/compiler/ref-preferences-errors-warnings.htm">Java Compiler Errors/Warnings Preferences</a>.
</li>
<li>
The Java Tutorials:
<a href="https://docs.oracle.com/javase/tutorial/java/generics/">Generics</a>,
<a href="https://docs.oracle.com/javase/tutorial/extra/generics/convert.html">Converting Legacy Code to Use Generics</a>.
</li>
</references>
</qhelp>