In recent versions of Java, yield
is a restricted identifier:
class T {
void yield() {}
{
yield();
}
}
$ javac --release 20 T.java
T.java:3: error: invalid use of a restricted identifier 'yield'
yield();
^
(to invoke a method called yield, qualify the yield with a receiver or type name)
1 error
To invoke existing methods called yield
, use qualified names:
class T {
void yield() {}
{
this.yield();
}
}
class T {
static void yield() {}
{
T.yield();
}
}
class T {
void yield() {}
class I {
{
T.this.yield();
}
}
}
Suppress false positives by adding the suppression annotation @SuppressWarnings("UnqualifiedYield")
to the enclosing element.