I am getting 2 errors on this simple piece of code:
public class Test {
public static void main(String args[]) {
O o = new O() {
};
}
}
Errors:
Test.java:3: cannot find symbol
symbol : class O
location: class Test
O o = new O() {
^
Test.java:3: cannot find symbol
symbol : class O
location: class Test
O o = new O() {
^
What is wrong here?
With anonymous inner classes you should extend an existing class (and use Polymorphism to override methods) or an existing interface.
With this rule, the code fails since there is NO existing class (type) O.
Try to define the class and use polymorphism to override the methods you want in the parent class.
As the comment says, you have to define the class somewhere. This code should work:
class O {}
public class Test {
public static void main(String args[]) {
O o = new O() {
};
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With