Optional Parameters in Java 8 Lambda Expressions
Join the DZone community and get the full member experience.Join For Free
Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway? Brought to you in partnership with IBM.
Yeah, they don't really exist, but we can use polymorphism, method overloading and default methods instead to make it a bit more convenient to use our APIs.
As an example, here's an event bus implementation where I can register event handlers with an optional header parameter.
Bus bus = new Bus(); bus.register(event -> System.out.println("I gots an event")); bus.register((event,header) -> System.out.println("I gots an event w/ header"));
Here are the dirty details on how you can do this (and - when dispatching - events, use default methods to avoid type coercion.
Opinions expressed by DZone contributors are their own.