<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">In brainstorming mode about fun that could be made possible with Java 8 and Java EE.<br class=""><br class="">Question in my mind is: is there some way we could make it possible for Lambdas or Method Refs to be CDI beans?<br class=""><br class="">It goes against the grain obviously as CDI creation is very much a “Don’t call us, we’ll call you” kind of thing. The VM dynamically creates a wrapper object around the Lambda or method reference and it implements the given interface.<br class=""><br class="">To make it work, there would need to be some non-producer method way of saying “put this thing in the context with these qualifiers”.<br class=""><br class="">Imagine a method somewhere that would allow you to:<br class=""><br class=""> public <T> void addObserver(java.util.function.Consumer<T> observer, Annotation... qualifiers);<br class=""><br class=""><br class="">Then you could take advantage as follows:<br class=""><br class=""> final List<URI> uris = new ArrayList<>();<br class=""> // @Observes URI<br class=""> addObserver((Consumer<URI>) uris::add);<br class=""><br class=""> // @Observes Thread<br class=""> addObserver(Runtime.getRuntime()::addShutdownHook);<br class=""><br class=""> // @Observes Runnable<br class=""> addObserver((Consumer<Runnable>) Executors.newFixedThreadPool(3)::submit);<br class=""><br class=""> // @Observes URI<br class=""> addObserver((Consumer<URI>) System.out::println, new AnnotationLiteral<Fine>() {<br class=""> });<br class=""><br class=""> // @Observes Handler<br class=""> final Logger logger = Logger.getLogger("somewhere");<br class=""> addObserver(logger::addHandler); // add handlers via event<br class=""><br class=""> // @Observes @Fine String<br class=""> addObserver((Consumer<String>) logger::fine, new AnnotationLiteral<Fine>() {});<br class=""> }<br class=""><br class=""><br class=""><br class="">-David<br class=""><br class=""><div apple-content-edited="true" class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><br class="Apple-interchange-newline"><br class=""></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class="">-- </div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class="">David Blevins<br class=""><a href="http://twitter.com/dblevins" class="">http://twitter.com/dblevins</a><br class="">http://www.tomitribe.com<br class=""></div>
</div>
<br class=""></body></html>