Sind statische Variablen in einer anonymen inneren Klasse erlaubt? Einige sagen nein, aber ich kann ohne Fehler in der S
Posted: 24 Feb 2025, 12:12
interface Workables {
void Work();
}
public class AnonymousTry {
public static void main(String[] args) {
Workables w = new Workables() {
static int x = 10;
public void Work() {
System.out.println("Working..."+x);
}
};
w.Work();
}
}
< /code>
Ich kann ohne Fehler in Eclipse ausführen, konnte aber nicht in Online -Compilern. Ich bin verwirrt darüber, ob die anonyme innere Klasse statische Variablen darin zulässt oder nicht.
void Work();
}
public class AnonymousTry {
public static void main(String[] args) {
Workables w = new Workables() {
static int x = 10;
public void Work() {
System.out.println("Working..."+x);
}
};
w.Work();
}
}
< /code>
Ich kann ohne Fehler in Eclipse ausführen, konnte aber nicht in Online -Compilern. Ich bin verwirrt darüber, ob die anonyme innere Klasse statische Variablen darin zulässt oder nicht.