<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="">Received via the spec-comments list.  Not a comment on any specific extant project; instead, a wish-list, and mostly stuff we’ve seen before â€” array literals, generic maps, union types.  <br class=""><div><br class=""><blockquote type="cite" class=""><div class="">Begin forwarded message:</div><br class="Apple-interchange-newline"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Jeremy Barrow <<a href="mailto:jeremy.a.barrow@gmail.com" class="">jeremy.a.barrow@gmail.com</a>><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">Subject: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><b class="">Small things Java lets you do, but not everywhere.</b><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">Date: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">August 13, 2018 at 6:59:33 AM EDT<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><a href="mailto:amber-spec-comments@openjdk.java.net" class="">amber-spec-comments@openjdk.java.net</a><br class=""></span></div><br class=""><div class=""><div class="">Heyo, I just wanted to send off a quick email about some of the things that<br class="">I think would be easy pickings for Amber to tackle.<br class="">More specifically, they're things in the language that are either not<br class="">completely fleshed out due to lack of interest, or, more likely, for some<br class="">technical reason.<br class=""><br class="">The first one is definitely array literals:<br class=""><br class="">I've been using Java for 7ish years at this point, and honestly, I don't<br class="">even know if I'm gonna get this right.<br class="">The only place I'm aware of array literals being valid is for a field write.<br class=""><br class="">Not many people use arrays, as Lists are just better, but _very_<br class="">occasionally you do have to reach for an array.<br class="">It would be nice if we could expand the array literal use case.<br class="">Just about everywhere an expression could be expected, I think an array<br class="">literal could be valid.<br class="">I can image `return` statements working really well with it, and with the<br class="">new expression switch, the break with value.<br class=""><br class=""><br class="">I'll be honest, this is where the "easy pickings" part is no longer true.<br class=""><br class=""><br class="">Class local generics (Field local generics?):<br class=""><br class="">I definitely think I'm not the only one who has written some static field<br class="">that has a map which maps some arbitrary data container to some value, with<br class="">the data container containing some type parameter that tells you what the<br class="">value type is.<br class=""><br class="">`private static final Map<Key<?>, ?> data = ...`<br class=""><br class="">It would be a massive boon, if we could write that as something like:<br class=""><br class="">`private static final <T> Map<Key<T>, T> data = ...`<br class=""><br class="">Otherwise we have to cast everything we pull out of the map.<br class="">I know it's of the correct type, but the compiler doesn't.<br class="">This leads to some annoying stuff where generics aren't actually helping<br class="">you, which is a bit counter intuitive.<br class="">We have generics for methods, theoretically, it should be possible for<br class="">fields.<br class=""><br class="">Union types:<br class="">Now, I'll preface this with this might be difficult to translate into the<br class="">VM right now, so erasure might be the only option for now (With type<br class="">signatures being a possible route in the future).<br class=""><br class="">In a nutshell, declaring fields with union types.<br class="">Right now, I either have to declare three different fields, making my<br class="">memory usage suffer if I have tons of these objects (Which I normally do,<br class="">because this specific class is a Token class for a lexer, and I parse<br class="">massive input sources), also making it more error prone due to having three<br class="">different ways to access the same data.<br class="">Granted union types won't solve the last problem, but it doesn't help it.<br class="">Technically, Java does have union types in catch signatures.<br class="">Obviously, the catch signatures kinda get "collapsed", so it's not really<br class="">the same, as there's a lot more needed under the hood here.<br class="">Possibly.<br class="">I think a quick prototype might be just to treat it as though I had written<br class="">something like, and just erase it to Object:<br class="">`private final <T extends String | Integer | Double> T data;`<br class="">Obviously, we don't have union generics, so that would obviously have to be<br class="">added, and honestly, I think that might be the can of worms I didn't plan<br class="">on.<br class=""><br class=""><br class="">So, I'll wrap it up there.<br class="">Obviously, the generics and union types are quite.. large in scope, and<br class="">aren't really easy, but I do think the array literals are something that<br class="">could be touched on.<br class=""><br class="">Cheers,<br class="">Jeremy.<br class=""></div></div></blockquote></div><br class=""></body></html>