Reputation: 817
Does the method class#getDeclaredFields()
return synthetic (compiler-generated) fields?
The Javadoc only says:
Returns an array of {@code Field} objects reflecting all the fields declared by the class or interface represented by this {@code Class} object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields.
Upvotes: 1
Views: 333
Reputation: 817
Apparently it does. Like @Matteo NNZ pointed out: An inner class generates a synthetic field for "this", so:
public class A {
public static void main(String[] args) {
System.out.println(B.class.getDeclaredFields()[0].isSynthetic());
}
class B {
}
}
prints true
.
Upvotes: 2