Java字节码签名 [英] Java Bytecode Signatures
问题描述
java.util.Arrays#parallelSort:< T :: Ljava / lang / Comparable< (TT;)V
java.util.Arrays#parallelSort:< T :: Ljava / lang / Comparable< -TT;> ;;>([TT; II)V
java.lang.Class#getAnnotation:< A :: Ljava / lang / annotation / Annotation;>(Ljava / lang / Class< TA;>;)TA;
java.lang.Class#getAnnotationsByType:< A :: Ljava / lang / annotation / Annotation;>(Ljava / lang / Class< TA;>;)[TA;
java.lang.Class#getDeclaredAnnotation:< A :: Ljava / lang / annotation / Annotation;>(Ljava / lang / Class< TA;>;)TA;
java.lang.Class#getDeclaredAnnotationsByType:< A :: Ljava / lang / annotation / Annotation;>(Ljava / lang / Class< TA;>)[TA;
java.util.Arrays#parallelSort:< T :: Ljava / lang / Comparable< -TT;> ;;>([TT;)V
java.util.Arrays#parallelSort:< ; T :: Ljava / lang / Comparable< -TT;> ;;>([TT; II)V
java.util.Collections#sort:< T :: Ljava / lang / Comparable< -TT ;> ;;>(Ljava / util / List< TT;> ;;)V
在这些类中的所有方法中,这些是唯一在其签名中具有 ::
的方法。我的问题是这个令牌的作用以及它为什么存在。
编辑
$ b
我知道 Java语言中的 ::
操作符,但这是Bytecode级别的。 p>
有一种定义的语法,从JSR 14开始更改为指定泛型类型的边界。
variable_name:class_type_bound:interface_type_bounds
因此,对于您的示例:
< T :: Ljava / lang / Comparable< TT;取代;>
其中反映:
< T扩展Comparable< T>>
变量名称是 T
,没有绑定类的类型,所以它被省略了,并且有一个类型为 Comparable< T>
的接口绑定
你所有的例子都遵循这一点,但有许多不同的形式:
< T:Ljava / lang / Object;>( Ljava / UTIL /收集和LT; TT;取代;)TT;
< T :: Ljava / lang / Comparable;>(Ljava / util / Collection< TT ;;)TT;
< T:Ljava / lang / Object;:Ljava / lang / Comparable;(Ljava / util / Collection< TT ;;)TT;
As part of the compiler for the programming language I am working on, I came across generic signatures in the bytecode, which I am trying to parse and convert to an AST. The parsing algorithm mostly works, but there seems to be a special case in which the format of these signatures behaves a bit strangely. Here are a few of these cases:
java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;)V
java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;II)V
java.lang.Class#getAnnotation: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)TA;
java.lang.Class#getAnnotationsByType: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)[TA;
java.lang.Class#getDeclaredAnnotation: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)TA;
java.lang.Class#getDeclaredAnnotationsByType: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)[TA;
java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;)V
java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;II)V
java.util.Collections#sort: <T::Ljava/lang/Comparable<-TT;>;>(Ljava/util/List<TT;>;)V
Out of all the methods in these classes, these are the only ones that have ::
in their signature. My question is what this token does and why it exists.
Edit
I know about the ::
operator in the Java Language, but this is something on the Bytecode level.
There is a defined syntax that changed as of JSR 14 to specify the bounds of a generic type.
variable_name:class_type_bound:interface_type_bounds
So for your example of:
<T::Ljava/lang/Comparable<-TT;>;>
Which would reflect:
<T extends Comparable<T>>
The variable name is T
, there is no class type bound so it was omitted, and there was an interface bound of type Comparable<T>
.
All your example follow this, but there any many different forms:
<T:Ljava/lang/Object;>(Ljava/util/Collection<TT;>;)TT;
<T::Ljava/lang/Comparable;>(Ljava/util/Collection<TT;>;)TT;
<T:Ljava/lang/Object;:Ljava/lang/Comparable;(Ljava/util/Collection<TT;>;)TT;
这篇关于Java字节码签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!