Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (10.2k points)

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

1 Answer

0 votes
by (46k points)

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.

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.

Related questions

0 votes
1 answer
asked Nov 25, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...