Embrace changes, pursue excellence, share niceness.
posted on 2008-03-26 10:35 pony 阅读(3666) 评论(3) 编辑 收藏 所属分类: Java
当且仅当该类为复合类时才返回 true 回复 更多评论
package test.base.cl; import java.lang.reflect.Modifier; /** * * @author wulingwudong */ public class SyntheticClass { private static class Inner { } public static void main(String[] args) { new Inner(); // checkSynthetic("test.base.cl.SyntheticClass"); // checkSynthetic("test.base.cl.SyntheticClass$Inner"); // checkSynthetic("test.base.cl.SyntheticClass$1"); Class[] c = SyntheticClass.class.getDeclaredClasses(); for(int i = 0;i < c.length;i++){ System.out.println(Modifier.toString(c[i].getModifiers())+" "+c[i].getName()+" ,synthetic:"+c[i].isSynthetic() ); } } static void checkSynthetic(String name) { try { Class c = Class.forName(name); System.out.println(name + " " + c.isSynthetic() + " "); } catch (ClassNotFoundException exc) { exc.printStackTrace(System.out); } } } 回复 更多评论
这个产生会在编译时产生一个isSynthetic()为true的类 回复 更多评论
Powered by: BlogJava Copyright © pony