Java anonymous inner class

Is there an instance of the anonymous inner class to store all available final variables, or does it only store the variables that are used inside the specified inner class? (i.e. does it do some kind of parsing? As far as I know, a reference to the parent instance is stored no matter what.)

+3


source to share


1 answer


The reference to the enclosing class is retained no matter what.



The final variables are stored as a copy, but only if you actually reference them somewhere in your inner class. This does not require much "parsing", but can be done at normal compilation time (the compiler must resolve the variable anyway, so it can also output the code to customize the copy).

+1


source







All Articles