Class InternalReflectUtil

java.lang.Object
dev.wyck.util.internal.InternalReflectUtil

@Internal public final class InternalReflectUtil extends Object
Internal class for quick reflective operations. This class isn't considered public API and may change at any time.
  • Method Details

    • field

      public static Field field(Class<?> owner, String fieldName)
    • get

      public static <T> T get(Field field, Object instance)
    • set

      public static void set(Field field, Object instance, Object value)
    • getFieldValue

      public static <T> T getFieldValue(Object instance, String fieldName)
    • setFieldValue

      public static void setFieldValue(Object instance, String fieldName, Object value)
    • shallowCopy

      public static <T> T shallowCopy(T instance)
      Creates a new instance of instance's class without running a constructor and copies every instance field across, inherited ones included. Referenced objects are shared rather than copied, so only the outer object is new.

      For varying an object per use when it has no constructor that takes its own fields -- such as a packet the server is sending to several players at once, where rewriting the original would leak one player's view to all of them.

      Parameters:
      instance - the object to copy
      Returns:
      a new object whose fields hold the same values