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
Post a Comment