Class InstanceField


  • public class InstanceField
    extends java.lang.Object
    Represents an accessible instance field. Contains the instance reference on which the field can be read and write.
    • Constructor Summary

      Constructors 
      Constructor Description
      InstanceField​(java.lang.reflect.Field field, java.lang.Object instance)
      Create a new InstanceField.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <A extends java.lang.annotation.Annotation>
      A
      annotation​(java.lang.Class<A> annotationClass)
      Returns the annotation instance for the given annotation type.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      boolean isAnnotatedBy​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Check if the field is annotated by the given annotation.
      boolean isNull()
      Check that the field is not null.
      boolean isSynthetic()
      Check if the field is synthetic.
      java.lang.reflect.Field jdkField()
      Returns the JDK Field instance.
      java.lang.String name()
      Returns the name of the field.
      java.lang.Object read()
      Safely read the field.
      private FieldReader reader()  
      void set​(java.lang.Object value)
      Set the given value to the field of this instance.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • field

        private final java.lang.reflect.Field field
      • instance

        private final java.lang.Object instance
    • Constructor Detail

      • InstanceField

        public InstanceField​(java.lang.reflect.Field field,
                             java.lang.Object instance)
        Create a new InstanceField.
        Parameters:
        field - The field that should be accessed, note that no checks are performed to ensure the field belong to this instance class.
        instance - The instance from which the field shall be accessed.
    • Method Detail

      • read

        public java.lang.Object read()
        Safely read the field.
        Returns:
        the field value.
        See Also:
        FieldReader
      • set

        public void set​(java.lang.Object value)
        Set the given value to the field of this instance.
        Parameters:
        value - The value that should be written to the field.
      • isNull

        public boolean isNull()
        Check that the field is not null.
        Returns:
        true if null, else false.
      • isAnnotatedBy

        public boolean isAnnotatedBy​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Check if the field is annotated by the given annotation.
        Parameters:
        annotationClass - The annotation type to check.
        Returns:
        true if the field is annotated by this annotation, else false.
      • isSynthetic

        public boolean isSynthetic()
        Check if the field is synthetic.
        Returns:
        true if the field is synthetic, else false.
      • annotation

        public <A extends java.lang.annotation.Annotation> A annotation​(java.lang.Class<A> annotationClass)
        Returns the annotation instance for the given annotation type.
        Type Parameters:
        A - Type of the annotation.
        Parameters:
        annotationClass - Tha annotation type to retrieve.
        Returns:
        The annotation instance.
      • jdkField

        public java.lang.reflect.Field jdkField()
        Returns the JDK Field instance.
        Returns:
        The actual Field instance.
      • name

        public java.lang.String name()
        Returns the name of the field.
        Returns:
        Name of the field.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object