Class RecordSupportInternal

java.lang.Object
org.apache.ignite.table.mapper.RecordSupportInternal

public final class RecordSupportInternal extends Object
Enables access to RecordSupport without reflection to provides utility methods to support records in Java 11.
  • Method Details

    • isRecord

      public static boolean isRecord(Class<?> clazz) throws IllegalAccessException
      Java 11 compatible, reflection based alternative, that returns true if and only if this class is a record class.

      Without reflection:

      
       Class<?> clazz;
       clazz.isRecord();
       
      Parameters:
      clazz - Class to check.
      Returns:
      true if and only if the given class is a record class.
      Throws:
      IllegalAccessException - If the record support methods could not be accessed.
    • getCanonicalConstructor

      public static <T> Constructor<T> getCanonicalConstructor(Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException
      Java 11 compatible, reflection based alternative to find the record canonical constructor.

      Without reflection:

      
       static <T extends Record> Constructor<T> getCanonicalConstructor(Class<T> cls)
           throws NoSuchMethodException {
         Class<?>[] paramTypes =
           Arrays.stream(cls.getRecordComponents())
                 .map(RecordComponent::getType)
                 .toArray(Class<?>[]::new);
         return cls.getDeclaredConstructor(paramTypes);
       }
       
      Type Parameters:
      T - Type of the record class.
      Parameters:
      clazz - Record class to find the canonical constructor for.
      Returns:
      Canonical constructor of the given record class.
      Throws:
      NoSuchMethodException - If the canonical constructor could not be found.
      InvocationTargetException - If a reflective record support method threw an exception.
      IllegalAccessException - If a reflective record support method could not be accessed.
      ClassNotFoundException - If java.lang.reflect.RecordComponent could not be resolved.