-1

Whenever I try to put an "instanceof" keyword it says it's an unexpected token . For information I ham using ArchLinux with an AUR java package.

public class TestZones {
    class A{}
    class B extends A{}
    A a = new A();
    B b = new B();
    if(b instanceof A){}
}

This syntax does it on the if.

Traxys
  • 85
  • 1
  • 1
  • 9

1 Answers1

1

Your if statement does not appear to be within a method or an initialization block,

public void doStuff() {
  if(b instanceof A){ // <-- like so
  }
}

or

{
  if(b instanceof A){ // <-- like so
  }
}
Community
  • 1
  • 1
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • @Traxys Thanks for editing your question, but my answer still appears to be correct. You aren't performing your test within a method or an initialization block. You'd get the same error on `if (1 == 1)` (or there's more code you need to post). – Elliott Frisch Aug 22 '14 at 14:57
  • Ok so that I did not think about , thanks for this problem that tortured my head for quite a bit :) – Traxys Aug 22 '14 at 15:12