-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathIncomparableEquals.qhelp
More file actions
39 lines (27 loc) · 983 Bytes
/
IncomparableEquals.qhelp
File metadata and controls
39 lines (27 loc) · 983 Bytes
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Calls of the form <code>x.equals(y)</code>,
where <code>x</code> and <code>y</code> have incomparable types,
should always return <code>false</code> because the runtime types
of <code>x</code> and <code>y</code> will be different.
Two types are incomparable if they are distinct
and do not have a common subtype.</p>
</overview>
<recommendation>
<p>Ensure that such comparisons use comparable types.</p>
</recommendation>
<example>
<p>In the following example, the call to <code>equals</code> on line 5 refers to the whole array by
mistake, instead of a specific element. Therefore, "Value not found" is returned.</p>
<sample src="IncomparableEquals.java" />
</example>
<references>
<li>
Java API Specification:
<a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)">Object.equals()</a>.
</li>
</references>
</qhelp>