Java Reference
In-Depth Information
curs, and (b) not shadowed (§ 6.4.1 ) at the place where the method invocation appears, to
determine if they are potentially applicable.
A member method is potentially applicable to a method invocation if and only if all of the
following are true:
• The name of the member is identical to the name of the method in the method in-
vocation.
• The member is accessible (§ 6.6 ) to the class or interface in which the method in-
vocation appears.
Whether a member method is accessible at a method invocation depends on
the access modifier ( public , none, protected , or private ) in the member's declara-
tion and on where the method invocation appears.
• If the member is a variable arity method with arity n , the arity of the method invoc-
ation is greater or equal to n -1 .
• If the member is a fixed arity method with arity n , the arity of the method invoca-
tion is equal to n .
• If the method invocation includes explicit type arguments, and the member is a
generic method, then the number of type arguments is equal to the number of type
parameters of the method.
This clause implies that a non-generic method may be potentially applicable to
an invocation that supplies explicit type arguments. Indeed, it may turn out to
be applicable. In such a case, the type arguments will simply be ignored.
This rule stems from issues of compatibility and principles of substitutability.
Since interfaces or superclasses may be generified independently of their sub-
types, we may override a generic method with a non-generic one. However,
the overriding (non-generic) method must be applicable to calls to the generic
method, including calls that explicitly pass type arguments. Otherwise the sub-
type would not be substitutable for its generified supertype.
If the search does not yield at least one method that is potentially applicable, then a
compile-time error occurs.
15.12.2.2. Phase 1: Identify Matching Arity Methods Applicable by Subtyping
Let m be a potentially applicable method (§ 15.12.2.1 ), let e 1 , ..., e n be the actual argument
expressions of the method invocation, and let A i be the type of e i (1 ≤ i n ). Then:
Search WWH ::




Custom Search