Java: Missing Features
Some of these, like reified generics, would be great, and it&#x27;s sad it&#x27;s too late to add them to the JVM. Some of these, like more expressive imports, seem pretty pointless given that we use IDE&#x27;s. But some of these are quite un-Javaish.<p>Structural typing would really go against the grain of the language, and i have a very hard time believing it would actually be useful. What method name is currently widely used with the same semantics across many classes, without being specified by an interface or base class? I can&#x27;t think of one. There used to be close(), but that&#x27;s been dealt with. Are there others?<p>Collection literals seem like a poor idea when there are so many different collection implementations. If i say:<p><pre><code>  List&lt;Integer&gt; list = {1, 2, 3};
</code></pre>
What kind of list do i get? ArrayList, as that&#x27;s the usual go-to? A foot-shooting opportunity for anyone doing concurrent programming! And a frustrating missed chance for anyone with a functional bent who would prefer an immutable list. Moreover, it seems unnecessary when you could easily just add constructors or factory methods like:<p><pre><code>  List&lt;Integer&gt; list = new ArrayList(1, 2, 3);
  List&lt;Integer&gt; list = ArrayList.of(1, 2, 3);
</code></pre>
Which leave the choice in the hands of the programmer for only a minimum of extra syntax.<p>Maps are a bit harder, because you need a way to describe pairs. In most projects i work on, i end up creating some helper methods that let me write:<p><pre><code>  Map&lt;String, Boolean&gt; map = map(entry(&quot;Java&quot;, true), entry(&quot;Go&quot;, false));
</code></pre>
And i wish there was a better syntax for that.<p>Something like algebraic data types would be good, though. You can already implement un-extendable classes using mild hacks:<p><pre><code>    public abstract class Shape {
    
        private Shape() {}
    
        public static class Circle {
            public static Circle of(int radius) {
                return new Circle(radius);
            }
    
            public final int radius;
    
            private Circle(int radius) {
                this.radius = radius;
            }
        }
    
        public static class Rectangle {
            public static Rectangle of(int width, int height) {
                return new Rectangle(width, height);
            }
    
            public final int width, height;
    
            private Rectangle(int width, int height) {
                this.width = width;
                this.height = height;
            }
        }
    
    }
</code></pre>
Because the constructors are all private, so putative subclass can&#x27;t call them. But you don&#x27;t get pattern matching, and of course it&#x27;s all rather verbose.<p>There are various madmen out on the edge of town trying to create terse approaches to this by meddling with forces beyond mortal knowledge:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;poetix&#x2F;mtuples" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;poetix&#x2F;mtuples</a><p>But i can&#x27;t see that going mainstream.