Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4984992

Alpha Feedback: Provide alias statement

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • specification
    • None
    • sparc
    • solaris_2.5


      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>;


            gbrachasunw Gilad Bracha (Inactive)
            jdriscol Jerry Driscoll (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: