File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Synthetic Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Synthetic Class" Watch "Synthetic Class" New topic

Synthetic Class

Luciano A. Pozzo
Ranch Hand

Joined: Jun 20, 2005
Posts: 112
What is a Synthetic Class?

(In a object of class "Class", exists a method called isSynthetic())

Rob Spoor

Joined: Oct 27, 2005
Posts: 20275

Actually, I'd like to know as well.

I've checked the language specs for Java6, and found only two occurrences of the word "synthetic". Of these two, only the following was relevant:
Any constructs introduced by the compiler that do not have a corresponding construct in the source code must be marked as synthetic, except for default constructors and the class initialization method.

What it means, I can't tell you though.

How To Ask Questions How To Answer Questions
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
According to the JVM Spec: "A class member that does not appear in the source code must be marked using a Synthetic attribute." Also, "The Synthetic attribute was introduced in JDK release 1.1 to support nested classes and interfaces."

I know that nested classes are sometimes implemented using synthetic fields and synthetic contructors, e.g. an inner class may use a synthetic field to save a reference to its outer class instance, and it may generate a synthetic contructor to set that field correctly. I'm not sure if it Java still uses synthetic constructors or methods for this, but I'm pretty sure I did see them used in the past. I don't know why they might need synthetic classes here. On the other hand, something like RMI or java.lang.reflect.Proxy should probably create synthetic classes, since those classes don't actually appear in source code. I just ran a test where Proxy did not create a synthetic instance, but I believe that's probably a bug.

Hmm, we discussed this some time ago back here. It seems like Sun is just ignoring this synthetic attribute, for classes at least, and we should too.
[ September 10, 2007: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Synthetic Class
It's not a secret anymore!