Created
July 5, 2019 10:10
-
-
Save mojo2012/da4e8193d25b1cb92bf416493022a09d to your computer and use it in GitHub Desktop.
This file contains 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
MiscUtils.java: | |
public static <T, C extends T> void with(T object, Class<C> asCastType, Consumer<C> consumer) { | |
consumer.accept((C) object); | |
} | |
I can be used like this: | |
BaseOpeningDay dayToBeSet = new OpeningDay(); | |
MiscUtil.with(dayToBeSet, OpeningDay.class, d -> { | |
d.setWeekday(DayOfWeek.SUNDAY); | |
}); | |
It allows you to both cast and assign at the same time AND it shortens the variable name to the assigned lamda argument name. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment