<p dir="ltr">Side note: lambda are serializable technically</p>
<div class="gmail_quote">Le 17 oct. 2015 15:04, &quot;John D. Ament&quot; &lt;<a href="mailto:john.d.ament@gmail.com">john.d.ament@gmail.com</a>&gt; a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Sven,<div><br></div><div>I&#39;m a little curious, why do they need to avoid serializable contexts?  In all honesty, I use app scoped functions, predicates in my code, at least in a couple of places.  Lambdas are specifically meant for operations, not data, so they should be in a highly reusable scope (in my opinion at least).</div><div><br></div><div>On the flip side, I have a hard time justifying needing to provide injectable beans for lambdas since good encapsulation should indicate they&#39;re only used in a single spot.</div><div><br></div><div>John</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Oct 17, 2015 at 7:51 AM Sven Linstaedt &lt;<a href="mailto:sven.linstaedt@gmail.com" target="_blank">sven.linstaedt@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Just one question: Who is on charge and is able of managing this unmanaged instances, e.g. lifecycle, serialization, concurrency (e.g. when dealing with closures)? </div><div><br></div><div>Functional programming and DI seem to be somehow disjunct in this case. E.g. manually setting up observers seem to better fit extension than normal application code. </div><div><br></div><div>On the other side, specifying producer methods or fields, that are injectable and return lambda expressions seems to be a no brainier for CDI, is not it? As long as they are not scoped in a serializable context. </div><div><br></div><div>Have a nice weekend </div><div>Sven<br><br><div>-- sent by phone</div></div></div><div dir="auto"><div><br>Am 17.10.2015 um 11:06 schrieb David Blevins &lt;<a href="mailto:david.blevins@gmail.com" target="_blank">david.blevins@gmail.com</a>&gt;:<br><br></div><blockquote type="cite"><div>In brainstorming mode about fun that could be made possible with Java 8 and Java EE.<br><br>Question in my mind is: is there some way we could make it possible for Lambdas or Method Refs to be CDI beans?<br><br>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><br>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><br>Imagine a method somewhere that would allow you to:<br><br>    public &lt;T&gt; void addObserver(java.util.function.Consumer&lt;T&gt; observer, Annotation... qualifiers);<br><br><br>Then you could take advantage as follows:<br><br>    final List&lt;URI&gt; uris = new ArrayList&lt;&gt;();<br>    // @Observes URI<br>    addObserver((Consumer&lt;URI&gt;) uris::add);<br><br>    // @Observes Thread<br>    addObserver(Runtime.getRuntime()::addShutdownHook);<br><br>    // @Observes Runnable<br>    addObserver((Consumer&lt;Runnable&gt;) Executors.newFixedThreadPool(3)::submit);<br><br>    // @Observes URI<br>    addObserver((Consumer&lt;URI&gt;) System.out::println, new AnnotationLiteral&lt;Fine&gt;() {<br>    });<br><br>    // @Observes Handler<br>    final Logger logger = Logger.getLogger(&quot;somewhere&quot;);<br>    addObserver(logger::addHandler); // add handlers via event<br><br>    // @Observes @Fine String<br>    addObserver((Consumer&lt;String&gt;) logger::fine, new AnnotationLiteral&lt;Fine&gt;() {});<br>    }<br><br><br><br>-David<br><br><div>
<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;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><br><br></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;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">-- </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;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">David Blevins<br><a href="http://twitter.com/dblevins" target="_blank">http://twitter.com/dblevins</a><br><a href="http://www.tomitribe.com" target="_blank">http://www.tomitribe.com</a><br></div>
</div>
<br></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>cdi-dev mailing list</span><br><span><a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a></span><br><span><a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a></span><br><span></span><br><span>Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.</span></div></blockquote></div>_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.</blockquote></div>
<br>_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br></blockquote></div>