Is this interface being instantiated? (Java 8) -


as far know, interfaces cannot instantiated directly. however, whenever compile following code:

interface {};  public class test {    public static void main(string[] args){        a = new a() {};        system.out.println(a); 

it outputs tostring() of object of class test:

test$16d06d69c 

and when change

a = new a() {}; 

to

a = new a(); 

it doesn't compile. why happening? interface being instantiated, or else happening behind scenes?

you defining new anonymous inline class implements interface statement:

a = new a() {}; 

and in same statement constructing new instance of new anonymous class definition.

so no not instantiating interface.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -