Tests whether one method, as a member of a given type,
overrides another method.
When a non-abstract method overrides an abstract one, the
former is also said to
implement the latter.
In the simplest and most typical usage, the value of the
type
parameter will simply be the class or interface
directly enclosing overrider
(the possibly-overriding
method). For example, suppose m1
represents the method
String.hashCode
and m2
represents Object.hashCode
. We can then ask whether m1
overrides
m2
within the class String
(it does):
assert elements.overrides(m1, m2,
elements.getTypeElement("java.lang.String"));
A more interesting case can be illustrated by the following example
in which a method in type
A
does not override a
like-named method in type
B
:
class A { public void m() {} }
interface B { void m(); }
...
m1 = ...; // A.m
m2 = ...; // B.m
assert ! elements.overrides(m1, m2,
elements.getTypeElement("A"));
When viewed as a member of a third type
C
, however,
the method in
A
does override the one in
B
:
class C extends A implements B {}
...
assert elements.overrides(m1, m2,
elements.getTypeElement("C"));
Returns:
{@code true} if and only if the first method overrides
the second
Parameters:
-
overrider - the first method, possible overrider
-
overridden - the second method, possibly being overridden
-
type - the type of which the first method is a member