What does the dollar sign at the end of a class me

2020-04-03 07:34发布

问题:

I am using Eclipse MAT to try and track down a resource leak in Android (if you change screen orientation a lot) and when I go to the histogram view, I see my activity listed along with the same activity listed again and again with a $ after it.

So like:

com.test.TestActivity
com.test.TestActivity$1
com.test.TestActivity$2
com.test.TestActivity$3

Just wondering what the $1, $2 and $3 means...

tia.

回答1:

They are anonymous inner classes.

For example:

Button button = (Button) findViewById(R.id.Button);  
button.setOnClickListener(new View.OnClickListener() {  
    public void onClick(View v) {  
        // ...
    }  
});

In this example the anonymous inner class is the subclass of View.OnClickListener.