Skip to content

Instantly share code, notes, and snippets.

@Goldmensch
Last active December 14, 2021 18:55
Show Gist options
  • Select an option

  • Save Goldmensch/a0787e56a6f9730345c9a03b054d88bc to your computer and use it in GitHub Desktop.

Select an option

Save Goldmensch/a0787e56a6f9730345c9a03b054d88bc to your computer and use it in GitHub Desktop.
((T) obj).method() Wrapper
public class Modifier<D> {
private final D data;
private Modifier(D data) {
this.data = data;
}
public static <D> Modifier<D> create(D data) {
return new Modifier(data);
}
@SuppressWarnings("unchecked") // totally fine
public <T, V> Modifier<D> set(BiConsumer<T, V> consumer, V value) {
consumer.accept((T) data, value);
return this;
}
public D get() {
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment