A yield statement yields a value as one of the results
of a generator method invocation (Section 16.2.2, “Generator Method Invocations”).
| Yield Statement | |||||
|---|---|---|---|---|---|
|
The type of the expression must be assignable to the declared return type
of the generator method declaration, or a compile-time error occurs.
The execution of a yield statement with
expression e is equivalent
to the sequential evaluation of the method invocation expression
c.consume(e),
where c is the implicit consumer parameter
of the generator method declaration (Section 11.2.1, “Generator Method Declarations”)
and the results of the invocation are discarded.