JDK-8061419 : Typedef (alias)
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Priority: P4
  • Status: Closed
  • Resolution: Other
  • Submitted: 2004-01-24
  • Updated: 2016-04-01
  • Resolved: 2014-10-17
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
One issue with generic which show pretty much immediatly when you start 
using them, is that it would be immensely practical to have some kind of 
alias statement, like C/C++ typedef.

Consider this code:

public class Example1 {
   private List<Pair<String,String>> internal;

   public Example1() {
     internal = new LinkedList<Pair<String,String>>();
   }

   public Collection<Pair<String,String>> getInternal() {
     return new HashSet<Pair<String,String>>(internal);
   }
}

This is both painful to read, and painful to write. Compare with this:

public class Example2 {
   public alias StringPair Pair<String,String>;

   private List<StringPair> internal;

   public Example2() {
     internal = new LinkedList<StringPair>();
   }

   public Collection<StringPair> getInternal() {
     return new HashSet<StringPair>(internal);
   }
}

As I see it, this would greatly reduce typing, and increase readability. 
The feature is not hard to implement, since it only concerns compile time 
transformation. The only issue would be that of a new key word, but this 
alternate syntax could get away from that too:

public StringPair = Pair<String,String>;

Comments
The 'specification' component of the Java Bug System is for reporting technical errors and ambiguities in the text of The Java Language Specification and The JVM Specification. It is not the venue to propose new features in the Java language or JVM. Ongoing feature development is carried out in OpenJDK (http://openjdk.java.net/jeps/); corresponding enhancements to The Java Language Specification and The JVM Specification are managed through the Java Community Process (http://jcp.org/).
17-10-2014

EVALUATION One of many requests for aliasing/implicit typing of long type names, especially those involving generics.
20-11-2006