Class Reflection


  • @Beta
    public final class Reflection
    extends Object
    Static utilities relating to Java reflection.
    Since:
    12.0
    • Method Detail

      • getPackageName

        public static String getPackageName​(Class<?> clazz)
        Returns the package name of clazz according to the Java Language Specification (section 6.7). Unlike Class.getPackage(), this method only parses the class name, without attempting to define the Package and hence load files.
      • getPackageName

        public static String getPackageName​(String classFullName)
        Returns the package name of classFullName according to the Java Language Specification (section 6.7). Unlike Class.getPackage(), this method only parses the class name, without attempting to define the Package and hence load files.
      • initialize

        public static void initialize​(Class<?>... classes)
        Ensures that the given classes are initialized, as described in JLS Section 12.4.2.

        WARNING: Normally it's a smell if a class needs to be explicitly initialized, because static state hurts system maintainability and testability. In cases when you have no choice while inter-operating with a legacy framework, this method helps to keep the code less ugly.

        Throws:
        ExceptionInInitializerError - if an exception is thrown during initialization of a class