supposing the following scenario:
void thisIsCalledManyTimes(){
// ....
someObject.executeIfNecessary( new Runnable(){
void run(){ //do sth here}
});
}
how much space would the anonymous object take? I understand that each object anonymous obj would have a pointer to the same implementation of run in its method lookup table.
The source code of Runnable doesn’t specify any fields, and so the anonymous class won’t take any more space than an
Object, with two differences. An inner class has an implicit reference to the outer class instance, so you would want to factor this in. It will also take copies offinalvariables referenced from the outer class.