简体   繁体   English

如何在Java中设置这些匿名类?

[英]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. 因此,我使用的反编译器不会反编译匿名类,因为Java编译器会将它们编译为单独的类。

So, I have a file called TitleScreen, and other files following with TitleScreen$1, TitleScreen$2. 因此,我有一个名为TitleScreen的文件,其他文件后面是TitleScreen $ 1,TitleScreen $ 2。 Simple. 简单。 But....why the numbers? 但是...为什么要数字? The class isn't named with an int, that's impossible. 该类没有以int命名,这是不可能的。 How would these be structured? 这些将如何构成? Do I just give them a random name like optionsClick(), worldsClick()? 我只是给他们一个随机名称,例如optionsClick(),worldsClick()吗?

Thanks! 谢谢!

Those are the names the Java compiler generates for anonymous classes. 这些是Java编译器为匿名类生成的名称。

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. 至于应该给反编译类起什么名字,我建议您将TitleScreen.Anon1,TitleScreen.Anon2设为内部类,或者将TitleScreen_Anon1用作自身的类。 That way you have some reference back to the original code if needed. 这样,如果需要,您可以参考一些原始代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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