java synthetic class

Synthetic class does not appear in your code, but made up by compiler. E.g. Bridge method made up by compiler in java is typically synthetic.

public class Pair<T> {
private T first;
private T second;
public void setSecond(T newValue) {
second = newValue;
}// Of seSecond
}// Of class Pair<T>


public class DateInterval extends Pair<String> {
public void setSecond(String second) {
System.out.println("OK sub");
}

public static void main(String[] args) throws NoSuchFieldException, SecurityException {

DateInterval interval = new DateInterval();
Pair pair = interval;
pair.setSecond("string1");
}
}
Using javap -verbose DateInterval instruction, u can see a bridge method

public void setSecond(java.lang.Object);
flags: ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
it is made up by compiler, however does not appear in your code.

版权声明:本文为concernings原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。