<div dir="ltr"><div dir="ltr">On Wed, Oct 16, 2024 at 10:33 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p dir="ltr">As for the upsides, my personal use case is that I plan to use this for annotations. There's a couple of benefits, like grouping relevant pieces of information and methods together under the same enum value. Using valueOf(), I can derive a lot of information back from it, allowing me to add a whole bunch of information with a single source of truth. That has been the cause of a lot of bugs for me lately, and the only way to achieve something similar is to do something like nested classes or fake an enum. Why not just use the real thing?</p></blockquote><div>Apologies, but I'm not completely understanding what you mean here. Annotations already support enum-valued properties, so what new capability would this change add?<br></div><div><br></div><div>While we're on the topic of what you can put in an annotation, I guess I'll throw this idea out there... (previously I was too scared :)</div><div><br></div><div>Idea: What about allowing lambda values for Class-valued annotation properties when the Class is a functional interface?</div><div><br></div><div>Example:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">public @interface GenericStringConstraint {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> Predicate<String> checker();</span></div><div style="margin-left:40px"><span style="font-family:monospace"> Function<String, String> errorGenerator() default s -> String.format("Invalid value \"%s\"", s);<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">}<br></span></div></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">public class Person {</span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace"> @</span><span style="font-family:monospace">GenericStringConstraint</span><span style="font-family:monospace">(checker = s -> !s.isEmpty() && Character.isUpperCase(s.charAt(0)))</span></div><div style="margin-left:40px"><span style="font-family:monospace"> public String getName() {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> ... // name must start with uppercase letter<br></span></div><div style="margin-left:40px"><span style="font-family:monospace"> }</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span></div><br><div>-Archie<br>
</div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>