I have a class implementing an interface. I don’t need a reference to objects of that class – only reference to their interfaces. It looks like:
interface A {}
class B : A {}
//in code:
A a = (A) new B();
My question is: Will instance of B to live (not collecting by GC) while I have a reference to A of that B?
Yes, because you still have a reference to that
new B()although you can see only the part that implements that interfaceA.