简体   繁体   中英

How Do I Set these Anonymous Classes Up in Java?

Okay, so recently I decompiled some code I had written years ago. So, the decompiler I use does not decompile the anonymous classes, since the Java compiler compiled them as separate classes.

So, I have a file called TitleScreen, and other files following with TitleScreen$1, TitleScreen$2. Simple. But....why the numbers? The class isn't named with an int, that's impossible. How would these be structured? Do I just give them a random name like optionsClick(), worldsClick()?

Thanks!

Those are the names the Java compiler generates for anonymous classes.

You can give them whatever name you want.

The compiler is more powerful than us mere programmers and can name classes with that funny syntax. Perhaps it does it that way cause it knows it is "safe": no user defined class (see comments below) is likely to have that name.

As for what you should name the decompiled classes, I'd suggest TitleScreen.Anon1, TitleScreen.Anon2 if you make them inner classes, or TitleScreen_Anon1 if their own classes. That way you have some reference back to the original code if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM