What is a synthetic class in Java? Why should it be used? How can I use it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.