Class TypeUtils

java.lang.Object
google.registry.util.TypeUtils

public final class TypeUtils extends Object
Utilities methods related to reflection.
  • Method Details

    • instantiate

      public static <T> T instantiate(Class<? extends T> clazz)
    • instantiate

      public static <T, U> T instantiate(Class<? extends T> clazz, U arg)
      Instantiate a class with the specified constructor argument.

      Because we use arg's type to look up the constructor, this only works if arg1's class is exactly the same type as the constructor argument. Subtypes are not allowed.

    • getClassFromString

      public static <T> Class<T> getClassFromString(String className, Class<T> expectedSuperType)
      Returns the class referred to by a fully qualified class name string.

      Throws an error if the loaded class is not assignable from the expected super type class.

    • getTypesafeEnumMapping

      public static <T> com.google.common.collect.ImmutableMap<String,T> getTypesafeEnumMapping(Class<T> clazz)
      Aggregates enum "values" in a typesafe enum pattern into a string->field map.
    • hasAnnotation

      public static Predicate<Class<?>> hasAnnotation(Class<? extends Annotation> annotation)
      Returns a predicate that tests whether classes are annotated with the given annotation.
    • checkNoInheritanceRelationships

      public static void checkNoInheritanceRelationships(com.google.common.collect.ImmutableSet<Class<?>> resourceClasses)