Search code examples
javainterfaceobject

This appears to create an object from an interface; how does it work?


interface Int {
   public void show();
}
Int t1 = new Int() {
   public void show() {
      System.out.println("message");
}

to.show();

Solution

  • You're defining an anonymous class that implements the interface Int, and immediately creating an object of type thatAnonymousClassYouJustMade.