United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4983159 Typedef (alias)
4983159 : Typedef (alias)

Details
Type:
Enhancement
Submit Date:
2004-01-24
Status:
Open
Updated Date:
2009-05-08
Project Name:
JDK
Resolved Date:
Component:
specification
OS:
solaris_2.5,linux,generic,windows_xp,windows_2000
Sub-Component:
language
CPU:
x86,sparc,generic
Priority:
P4
Resolution:
Unresolved
Affected Versions:
1.2.0,1.3.0,1.4.0,1.4.1,1.4.2,5.0,6
Targeted Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

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
EVALUATION

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



Hardware and Software, Engineered to Work Together