Dollar sign ($) after the name of the activity class in Android logs (non-anonymous inner class)

I look through some crash logs for my application, and the stack trace shows something like:

at MyActivity.formatDouble(MyActivity.java:182)
at MyActivity.access$47(MyActivity.java:196)    
at MyActivity$28.onCameraChange(MyActivity.java:167)

"MyActivity" is an activity and therefore not an anonymous inner class. I can’t be sure of the dollar sign on line No. 3 (and on line # 2, too)

+4
source share
1 answer

I suspect that line 167 is inside an anonymous class inside MyActivity, but access$47is just a trampoline method, allowing you to onCameraChangecall a private method on MyActivity. (The JVM did not allow this, so the Java compiler creates a method that allows it.)

Java Android:

public class Test {

    private static void privateMethod() {
        throw new RuntimeException();
    }

    public static void main(String[] args) throws Exception {
        Runnable runnable = new Runnable() {
            @Override public void run() {
                privateMethod();
            }
        };
        runnable.run();
    }
}

, , :

Exception in thread "main" java.lang.RuntimeException
        at Test.privateMethod(Test.java:4)
        at Test.access$000(Test.java:1)
        at Test$1.run(Test.java:10)
        at Test.main(Test.java:13)

Test$1.run main, access$000 privateMethod.

+7

All Articles