What does the .access $ XXXX number mean?

I have a line in the stack, for example, "at alexei.ATable $ IndexOfATable.access $ 1400 (ATable.java:80)"

And I wonder what the number 1400 is? The inner class IndexOfATable has only 3 fields, not 1400.

I wonder why the number 1400 is so large?

debug: Exception in thread "main" java.lang.NullPointerException at alexei.ATable$IndexOfATable.compareTwoRows(ATable.java:181) at alexei.ATable$IndexOfATable.access$1400(ATable.java:80) at alexei.ATable.updateIndex(ATable.java:501) at alexei.ATable.addRow(ATable.java:361) at learn.Base.main(Base.java:18) Java Result: 1 
+6
source share
1 answer

This is a synthetic method that the compiler generates to work with the inner class. Java bytecode does not have the concept of an inner class, so when it is compiled it performs various tricks to "fake" the presence of one at runtime. In this particular case, the access$XXX method class is usually associated with providing a reference to the outer class from the inner. Such synthetic entities are signs of this. (You can usually determine them by the presence of a dollar in the class / method name.)

Why is the number 1400 so large?

This is a purely arbitrary identifier that only the compiler should know about (and therefore chooses). While it is unique in the application, it can be anything (technically speaking, it should not even be a number.)

As for the problem, look at the line indicated on the top line of the stack trace: ATable.java:181 .

+15
source

Source: https://habr.com/ru/post/945827/


All Articles