本文介绍了Java 中的合成类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中的合成类是什么?为什么要使用它?我该如何使用它?

What is a synthetic class in Java? Why should it be used? How can I use it?

推荐答案

例如,当您有一个 switch 语句时,java 创建一个以 $ 开头的变量.如果您想看到这样的示例,请查看其中包含 switch 语句的类的 Java 反射.当您在类中的任何地方至少有一个 switch 语句时,您就会看到这些变量.

For example, When you have a switch statement, java creates a variable that starts with a $. If you want to see an example of this, peek into the java reflection of a class that has a switch statement in it. You will see these variables when you have at least one switch statement anywhere in the class.

为了回答您的问题,我认为您无法访问(反射除外)合成类.

To answer your question, I don't believe you are able to access(other than reflection) the synthetic classes.

如果您正在分析一个您一无所知的类(通过反射)并且需要了解关于该类的非常具体和低级的事情,那么您最终可能会使用与合成相关的 Java 反射方法类.此处唯一的用途"是获取有关该类的更多信息,以便在您的代码中适当地使用它.

If you are analyzing a class that you don't know anything about (via reflection) and need to know very specific and low-level things about that class, you may end up using Java reflection methods that have to do with synthetic classes. The only "use" here is get more information about the class in order to use it appropriately in your code.

(如果您这样做,您可能正在构建其他开发人员可以使用的某种框架.)

(If you're doing this, you're probably building a framework of some sorts that other developers could use. )

否则,如果您不使用反射,则我所知道的合成类没有实际用途.

Otherwise, if you are not using reflection, there are no practical uses of synthetic classes that I know of.

这篇关于Java 中的合成类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:35