Java Reference
In-Depth Information
A generic method declaration defines a set of methods, one for each possible invocation of
the type parameter section by type arguments. Type arguments may not need to be provided
8.4.5. Method Return Type
The
result
of a method declaration either declares the type of value that the method returns
(the
return type
), or uses the keyword
void
to indicate that the method does not return a
value.
Result:
Type
void
Return types may vary among methods that override each other if the return types are ref-
erence types. The notion of return-type-substitutability supports
covariant returns
, that is,
the specialization of the return type to a subtype.
A method declaration
d
1
with return type
R
1
is
return-type-substitutable
for another method
d
2
with return type
R
2
, if and only if the following conditions hold:
• If
R
1
is
void
then
R
2
is
void
.
• If
R
1
is a primitive type, then
R
2
is identical to
R
1
.
• If
R
1
is a reference type then:
♦
R
1
is either a subtype of
R
2
or
R
1
can be converted to a subtype of
R
2
by un-
♦
R
1
= |
R
2
|
An unchecked conversion is allowed in the definition, despite being unsound,
as a special allowance to allow smooth migration from non-generic to generic
code. If an unchecked conversion is used to determine that
R
1
is return-type-
substitutable for
R
2
, then
R
1
is necessarily not a subtype of
R
2
and the rules for
8.4.6. Method Throws