Skip to main content

Where is the "access" literal for inner classes documented?

2 replies [Last post]
Joined: 2006-05-05

I'm writing a custom logger, and using reflection to get the class and method names.
Often, methods of inner classes, anonymous or not, have the form


"access" has got to be one of the most common strings in the Java specification, and I can't find exactly where, and when this is generated.

Section "13.1 The Form of a Binary" tells me about the use of "$" following the binary name, but is the literal "access" implementation dependent, or part of the spec?

Can someone five me a pointer?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-11-01

access$xxxxx are generated methods are not part of the language and as such don't follow any spec AFAIK.

They are generated as the JVM doesn't directly support outer/inner/nested classes accessing private fields, method and constructors, even though Java does.
To get around this the compiler creates accessor methods for you to get/set fields, call methods and call constructors.

Generally the JVM can optimise this out, so there may not be any performance overhead.

In short, if they annoy you, change your private members which are accessed in other classes to package local and they won't be generated.

Joined: 2006-05-05


It's not that I don't like them, it's just that I was forced to put the following in my logger code:
ignore == ignore && methodName.startsWith("access$"));

In other words, as I travel back through the stack frames, looking for the method that called the logger, I must explicitly ignore these generated names. I did not like doing that without more understanding.