Closed jimshowalter closed 4 months ago
You want to use setsField
, not onField
. Also, you likely want to make the constructor public in defineConstructor
.
How do I specify the field that it sets in setsField, when that field is being dynamically added in the same builder chain?
Create a latent field description and supply it.
This works:
.defineConstructor(Visibility.PUBLIC)
.intercept(
MethodCall.invoke(getConstructor(entityClass))
.onSuper()
.andThen(
FieldAccessor.ofField(MODIFIED_FIELDS_TRACKER_FIELD_NAME)
.setsValue(new HashSet<String>())))
This fails with "Exception in thread "main" java.lang.IllegalStateException: Cannot invoke public java.util.HashSet() on private final java.util.Set org.foo.bytebuddyctor.Entity2$Setter$Tracking$ByteBuddy$Subclass._modified$Fields$Tracker".
What am I doing wrong?