Java Reference
In-Depth Information
Ask the Expert
Q :
How do I specify a method reference to a generic method?
A : Often, because of type inference, you won't need to explicitly specify a type argu-
ment to a generic method when obtaining its method reference, but Java does include
a syntax to handle those cases in which you do. For example, assuming the follow-
ing:
the following statement is valid:
Here, the type argument for the generic method myGenMeth is explicitly specified.
Notice that the type argument occurs after the :: . This syntax can be generalized: When a
generic method is specified as a method reference, its type argument comes after the ::
and before the method name. In cases in which a generic class is specified, the type argu-
ment follows the class name and precedes the :: .
The output is shown here:
Search WWH ::




Custom Search