0

Would someone be able to explain the meaning of what is going on in isOk the inner anonymous class? I understand the instance of comparison, but I don't understand the

"BlackHole.this.encloses". 

BlackHole inherits an

encloses(...) 

method, fyi.

Does this mean to use BlackHole's "this" instead of the anonymous class' "this"?

public class BlackHole extends Simulton {
    private int radius = 10;
    private ColoredCircle image;
    private RemoveBehavior remove;

    ...
    ...

    private final class  implements Decision {
        public boolean isOK(Object o) {
            return o instanceof Prey && BlackHole.this.encloses(((Simulton)o).getLocation());
        }
    }
}

From the comments: There's also this in the constructor:

this.remove = new RemoveBehavior(new BlackHole.()); 

Does "BlackHole.()" imply calling the constructor of the anonymous inner class? (RemoveBehavior expects a Decision). I've never seen ".()" before.

newbie
  • 607
  • 2
  • 8
  • 16
  • 6
    Yes, see http://stackoverflow.com/questions/9043170/java-calling-outer-class-method-in-anonymous-inner-class – rogerdpack Dec 13 '15 at 22:50
  • Yes, but if the anonymous inner class has no `encloses(...)` method of its own, then the `BlackHole.this` is superfluous and thus completely unnecessary. – Hovercraft Full Of Eels Dec 13 '15 at 22:51
  • Thanks! There's also this in the constructor: this.remove = new RemoveBehavior(new BlackHole.()); Does "BlackHole.()" imply calling the constructor of the anonymous inner class? (RemoveBehavior expects a Decision) – newbie Dec 13 '15 at 22:58

0 Answers0