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.

猜你喜欢

转载自zhengkunsheng.iteye.com/blog/2381261
今日推荐