Can Scala 2.10 reflection emulate this Javassist functionality?

最后都变了- 提交于 2019-12-10 18:16:26

问题


I would like to know if it is possible to rewrite this function using Scala-2.10 reflection instead of Javassist:

def adaptClass(name1: String, name2: String) : Class[_] = {
  import javassist._
  val cls = ClassPool.getDefault().getAndRename(name1, name2)
  val field = CtField.make("private static final long serialVersionUID = 1L;", cls))
  cls.addField(field, cls))
  cls.toClass()
}

I am most interested in the part that adds a SerialVersionUID field to the new class, since that part of the above code does not actually work correctly for Scala classes. The key point is that we the field being added is static final.

来源:https://stackoverflow.com/questions/17384913/can-scala-2-10-reflection-emulate-this-javassist-functionality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!