Class FieldAccess<T>

java.lang.Object
com.opencsv.bean.FieldAccess<T>
Type Parameters:
T - The type of the member variable being accessed

public class FieldAccess<T> extends Object
Encapsulates the logic for accessing member variables of classes.

The logic in opencsv is always:

  1. Use an accessor method first, if available, and this always has the form "get"/"set" + member name with initial capital.
  2. If this accessor method is available but deals in Optional, wrap or unwrap as necessary. Empty Optionals lead to null return values, and null values lead to empty Optionals.
  3. Use reflection bypassing all access control restrictions.
These are considered separately for reading and writing.

Since:
5.0
  • Field Details

    • field

      private final Field field
      The field being accessed.
    • accessor

      private final AccessorInvoker<Object,T> accessor
      A functional interface to read the field.
    • assignment

      private final AssignmentInvoker<Object,T> assignment
      A functional interface to write the field.
  • Constructor Details

    • FieldAccess

      public FieldAccess(Field field)
      Constructs this instance by determining what mode of access will work for this field.
      Parameters:
      field - The field to be accessed.
  • Method Details

    • determineAccessorMethod

      private AccessorInvoker<Object,T> determineAccessorMethod()
    • determineAssignmentMethod

      private AssignmentInvoker<Object,T> determineAssignmentMethod()
    • getField

      public T getField(Object bean) throws IllegalAccessException, InvocationTargetException
      Returns the value of the field in the given bean.
      Parameters:
      bean - The bean from which the value of this field should be returned
      Returns:
      The value of this member variable
      Throws:
      IllegalAccessException - If there is a problem accessing the member variable
      InvocationTargetException - If there is a problem accessing the member variable
    • setField

      public void setField(Object bean, T value) throws IllegalAccessException, InvocationTargetException
      Sets the value of the field in the given bean.
      Parameters:
      bean - The bean in which the value of the field should be set
      value - The value to be written into the member variable of the bean
      Throws:
      IllegalAccessException - If there is a problem accessing the member variable
      InvocationTargetException - If there is a problem accessing the member variable
    • hashCode

      public int hashCode()
      Creates a hash code for this object. This override delegates hash code creation to the field passed in through the constructor and does not includes any of its own state information.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Determines equality between this object and another. This override delegates equality determination to the field passed in through the constructor and does not includes any of its own state information.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Returns a string representation of this object. This override delegates the string representation to the field passed in through the constructor and does not includes any of its own state information.
      Overrides:
      toString in class Object