Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. MiscUtils.java:
  2.  
  3. public static <T, C extends T> void with(T object, Class<C> asCastType, Consumer<C> consumer) {
  4. consumer.accept((C) object);
  5. }
  6.  
  7. I can be used like this:
  8.  
  9. BaseOpeningDay dayToBeSet = new OpeningDay();
  10.  
  11. MiscUtil.with(dayToBeSet, OpeningDay.class, d -> {
  12. d.setWeekday(DayOfWeek.SUNDAY);
  13. });
  14.  
  15. It allows you to both cast and assign at the same time AND it shortens the variable name to the assigned lamda argument name.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement