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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -