Class ClassNamesUtil


  • public final class ClassNamesUtil
    extends Object
    When dealing with classes we have to handle a bunch of different kinds of names. From higher level to lower level:
    • Canonical name: a.b.C.D
    • Binary name: a.b.C$D
    • Internal name: a/b/C$D

    Canonical names are on the Java language level. They are how you type a reference to a class from an another arbitrary class. Some classes may not even have one, eg local classes cannot be referenced from outside their scope.

    Binary names lift the ambiguity between inner class selection and package name that exists in canonical names. They're more convenient to work with when loading classes. They're typically the kind of name you find when using reflective APIs.

    Internal names are burned into class files are they allow getting a file path to the referenced class file just by appending .class. They are only useful at the level of class files, eg when using ASM.

    Type descriptors are another class of "names" that use internal names, but are more general, as they can represent all kinds of types. Eg the type descriptor for class a.b.C.D is La/b/C$D;, the one of boolean is Z, and the one of boolean[] is [Z.

    Type signatures are a superset of type descriptors that can also represent generic types. These need to be parsed when reading info from a class file.

    • Method Detail

      • getTypeDescriptor

        public static String getTypeDescriptor​(Class<?> klass)
      • getInternalName

        public static String getInternalName​(Class<?> klass)
      • internalToBinaryName

        public static String internalToBinaryName​(String internal)
      • classDescriptorToBinaryName

        public static String classDescriptorToBinaryName​(String descriptor)
      • classDescriptorToInternalName

        public static String classDescriptorToInternalName​(String descriptor)
      • binaryToInternal

        public static String binaryToInternal​(String binary)