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.
The method signature in java is defined as the structure of the method that is designed by the programmer. The method signature is the combination of the method name and the parameter list. The method signature depicts the behavior of the method i.e types of values of the method, return type of the method, etc.
What Is the Bytecode? Bytecode is the intermediate representation of a Java program, allowing a JVM to translate a program into machine-level assembly instructions. When a Java program is compiled, bytecode is generated in the form of a . class file.
V in a type signature means void type. Bytecode does not differentiate constructors from other methods (other than using special method name).
A signature is a list that specifies a class constructor, an instance method, or a static method, thereby distinguishing it from other constructors, instance methods, or static methods.
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;
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With