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 -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -