Class InternalReflectUtil
java.lang.Object
dev.wyck.util.internal.InternalReflectUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic Fieldstatic <T> Tstatic <T> TgetFieldValue(Object instance, String fieldName) static voidstatic voidsetFieldValue(Object instance, String fieldName, Object value) static <T> TshallowCopy(T instance) Creates a new instance ofinstance's class without running a constructor and copies every instance field across, inherited ones included.
-
Method Details
-
field
-
get
-
set
-
getFieldValue
-
setFieldValue
-
shallowCopy
public static <T> T shallowCopy(T instance) Creates a new instance ofinstance'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
-