什么是ScalaSignature? [英] What is a ScalaSignature?

查看:359
本文介绍了什么是ScalaSignature?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Scala文件反编译为Java代码时,经常会遇到用 ScalaSignature s注释的类.这些似乎只有一个注释值,即某种程度上已编码的String.为什么Scala编译器会创建这样的奇数构造,而不是在 class 文件中使用自定义的 Attribute ?

When decompiling Scala files to Java code, one often comes across classes that are annotated with the ScalaSignatures. These seem to only have one annotation value, a somewhat encoded String. Why does the Scala Compiler create such an odd construct, instead of using custom Attributes in the class file?

推荐答案

来自将腌制的Scala签名存储在类文件中:

遗产签名存储方法作为属性同时更优雅更紧凑(约15%)和更简单比起使用注解但是,访问腌制的签名在属性中要求获取和解析这整个类文件.由于注释可以被JVM识别,因此新方法允许检索腌制签名个字节直接从内部一个正在运行的Scala程序通过使用Java反射.

The legacy method for storing signatures as attributes is simultaneously more elegant, more compact (about 15%) and simpler than that using annotations. However, to access the pickled signature in attributes requires obtaining and parsing the entire class file. Because annotations are recognized by the JVM, the new method allows retrieving pickled signature bytes directly from within a running Scala program by using Java reflection.

新方法是正在编写的正在进行的开发的一部分一种好的斯卡拉反射图书馆.Java反射意见斯卡拉节目在一种简化的以Java为中心的方式.给一个反射程序的以Scala为中心的视图,Java反射提供的信息必须完成与在中找到的信息Scala签名.这遗产储存方式本来需要全部要解析的类文件再次-JVM已经解析了它们并通过反思展示其大部分内容.新的存储方法允许进入腌的Scala签名与其他反射信息相同的方式是可以使新的Scala反射库更简单,更快.

The new method is part of an ongoing development to write a good Scala reflection library. Java reflection views Scala programs in a simplified Java-centric way. To give a Scala-centric view of the reflected program, information provided by Java reflection must be completed with information found in Scala signatures. The legacy storage method would have required all class files to be parsed again — the JVM has parsed them already and exposes most of their content through reflection. The new storage method allows accessing pickled Scala signatures in the same way than other reflective information is obtained, making the new Scala reflection library simpler and faster.

虽然Scala反射库不会成为2.8版本的一部分,但它是可取的那现存的2.8类文件与新的反射库兼容可用的.此外,由于2.8类文件与2.7类文件不兼容任何状况之下,改变中存放方法签名在2.8中不需要其他二进制不兼容类文件格式改变不久之后.

Whilst the Scala reflection library will not be part of the 2.8 release, it is desirable that existing 2.8 class files are compatible with the new reflection library when it becomes available. Furthermore, since 2.8 class files are incompatible with those of 2.7 in any case, changing the method of storing signatures in 2.8 will not require another binary-incompatible class file format change shortly after.

这篇关于什么是ScalaSignature?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆