Last active
December 14, 2021 18:55
-
-
Save Goldmensch/a0787e56a6f9730345c9a03b054d88bc to your computer and use it in GitHub Desktop.
((T) obj).method() Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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