Is there Scala aware high level byte-code manipulation tool like Javassist?

馋奶兔 提交于 2019-12-12 10:29:16

问题


I am looking for a high level bytecode manipulation tool like Javassist, but that understands some of Scala peculiarities. Lower level bytecode manipulation tools should be relatively agnostic, but for my use cases something at the level of Javassist is much better. However a tool at that level needs to know about the source language and its bytecode mapping. Does something like this exist for Scala? So far I have been able to use Javassist with Scala for very simple things, but I have been bitten by some Scala/Java differences for a couple of other things.


回答1:


I don't think that such a tool exists (yet). The current situation is, that you cannot mix compilation units compiled with different versions of Scala, i.e. a class compiled with Scala 2.9 will not interoperate with a class compiled with Scala 2.10.

When you use Scala 2.10, you can use Scala reflection and Scala macros to reach similar goals as with bytecode modification. For me this looks like the most future proof way.

One of your questions aimed at adding a serial version ID. This should definitely be possible with Scala macros. With Scala macros it shoudl even be possible to manage the serial version ids in an external database according to API changes.



来源:https://stackoverflow.com/questions/17535971/is-there-scala-aware-high-level-byte-code-manipulation-tool-like-javassist

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