posted 6 years ago
You can only "instantiate an interface" if you supply implementations for all its methods. What actually gets instantiated is an anonymous class that happens to implement this interface. If you compile this code, you'll see that there's an extra class file being created called something like "Test$1.class" (assuming that this code is part of the Test class) - Test$1 is the anonymous class that implements the interface and which gets instantiated. So this notation is merely a syntactic shortcut so you don't have to declare an actual class.