<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hi John</div><div><br></div><div>most, if not all Java 8 lambda types are not serializable afaik (sure, one can specify custom serializable lambdas, but I guess this happens rather rarely), so assigning a lambda typed bean a serializable context will probably always cause problems. Even the lamda type itself is serializable, it does not mean it's closure is. Even though application scoped lambda beans are in general no problem at all, most other contexts are. So the question is, whether to allow lambda typed bean to have any serializable scope at all.&nbsp;</div><div><br></div><div>Don't get me wrong. I am a huge fan of Java 8 and functional programming in general, but I think FP's way of expressive design somehow collides with CDI's rather declarative style. At least for non-SPI code.&nbsp;</div><div><br></div><div>Best regards</div><div>Sven</div><div><br><div>-- sent by phone</div></div><div><br>Am 17.10.2015 um 15:03 schrieb John D. Ament &lt;<a href="mailto:john.d.ament@gmail.com">john.d.ament@gmail.com</a>&gt;:<br><br></div><blockquote type="cite"><div><div dir="ltr">Sven,<div><br></div><div>I'm a little curious, why do they need to avoid serializable contexts?&nbsp; In all honesty, I use app scoped functions, predicates in my code, at least in a couple of places.&nbsp; 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'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">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)?&nbsp;</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.&nbsp;</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.&nbsp;</div><div><br></div><div>Have a nice weekend&nbsp;</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.&nbsp; 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> &nbsp;&nbsp;&nbsp;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> &nbsp;&nbsp;&nbsp;final List&lt;URI&gt; uris = new ArrayList&lt;&gt;();<br> &nbsp;&nbsp;&nbsp;// @Observes URI<br> &nbsp;&nbsp;&nbsp;addObserver((Consumer&lt;URI&gt;) uris::add);<br><br> &nbsp;&nbsp;&nbsp;// @Observes Thread<br> &nbsp;&nbsp;&nbsp;addObserver(Runtime.getRuntime()::addShutdownHook);<br><br> &nbsp;&nbsp;&nbsp;// @Observes Runnable<br> &nbsp;&nbsp;&nbsp;addObserver((Consumer&lt;Runnable&gt;) Executors.newFixedThreadPool(3)::submit);<br><br> &nbsp;&nbsp;&nbsp;// @Observes URI<br> &nbsp;&nbsp;&nbsp;addObserver((Consumer&lt;URI&gt;) System.out::println, new AnnotationLiteral&lt;Fine&gt;() {<br> &nbsp;&nbsp;&nbsp;});<br><br> &nbsp;&nbsp;&nbsp;// @Observes Handler<br> &nbsp;&nbsp;&nbsp;final Logger logger = Logger.getLogger("somewhere");<br> &nbsp;&nbsp;&nbsp;addObserver(logger::addHandler); // add handlers via event<br><br> &nbsp;&nbsp;&nbsp;// @Observes @Fine String<br> &nbsp;&nbsp;&nbsp;addObserver((Consumer&lt;String&gt;) logger::fine, new AnnotationLiteral&lt;Fine&gt;() {});<br> &nbsp;&nbsp;&nbsp;}<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">--&nbsp;</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>
</div></blockquote></body></html>