If the usage of "new" keyword in Java implies memory allocation, why is it not the case for an anonymous inner class? -
as beginner in java, i've been taught usage of "new" keyword leads invocation of constructor , thereby memory allocation object. if indeed case, happens when write:
button.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { // something. } }); ??
if memory allocated, not violating concept of "interfaces cannot instantiated"? there no memory allocation new actionlistener? if no memory allocated, how accessed when not specifying object reference? or, act exception "memory allocation @ 'new'" rule??
in case anonymous(name chosen compiler) class created default constructor , implicitly implemented interface of actionlistener , happily instantiated other class create new keyword.
Comments
Post a Comment