java synthetic class_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java synthetic class

java synthetic class

 2017/6/25 5:32:34  zhengkunsheng  程序员俱乐部  我要评论(0)
  • 摘要:Syntheticclassdoesnotappearinyourcode,butmadeupbycompiler.E.g.Bridgemethodmadeupbycompilerinjavaistypicallysynthetic.publicclassPair<T>{privateTfirst;privateTsecond;publicvoidsetSecond(TnewValue){second=newValue;}//OfseSecond}//OfclassPair<
  • 标签:Java 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.
发表评论
用户名: 匿名