myNum. Thus, when test() is called through that reference, as shown here:
the method will call isFactor() on myNum, which is the object specified when the
method reference was created. The same situation occurs with the method reference
myNum2::isFactor, except that isFactor() will be called on myNum2. This is
confirmed by the output.
It is also possible to handle a situation in which you want to specify an instance method
that can be used with any object of a given class—not just a specified object. In this
case, you will create a method reference as shown here:
Dostları ilə paylaş: