Does it make sense to let the class implement an i...
# announcements
p
Does it make sense to let the class implement an interface instead of using an anonymous inner class - in regards to object allocation?
e
Yes. It saves one allocation. If the class is private or internal and is not part of some widely-used API, then it makes sense.
p
Why doesn't it make sense on a widely used API?
This is the case I'm talking about:
e
If the class is a part of public API and it implements some listeners interface, then it leaks its implementation details (and what happens if client just invokes a method of that listener interface?)
One word here: encapsulation
p
I'm only taking about memory / performance, not API design