`

Javassit初探

 
阅读更多

官网/参考: http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/ 

https://github.com/jboss-javassist/javassist

http://www.ibm.com/developerworks/cn/java/coretech/java-dynamic.html

 

ClassPool classPool = ClassPool.getDefault();
ClassClassPath classPath = new ClassClassPath(SpringContextHolder.class);
classPool.insertClassPath(classPath);

CtClass strCtClass = classPool.get("java.lang.String");
for (Element ele : typeAliases) {
	Attribute attribute = ele.attribute("type");
	String className = attribute.getValue();
	if (className.endsWith("Dto")) {
		CtClass ctClass = classPool.get(className);
		CtField ctField = new CtField(strCtClass, ShardUtils.SHARD_TABLE_VARIABLE_NAME, ctClass);
		ctField.setModifiers(Modifier.PUBLIC);
		ctClass.addField(ctField);
		ctClass.toClass();
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics