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

Refator Type.Mapping to be more lambda-friendly

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • None
    • tools

      Javac defines this abstract class in Type:

      public static abstract class Mapping {
              private String name;
              public Mapping(String name) {
                  this.name = name;
              }
              public abstract Type apply(Type t);
              public String toString() {
                  return name;
              }
          }

      This abstract class is essentially treated as a functional interface:

                  Mapping boxMap = new Mapping("boxMap") {
                      @Override
                      public Type apply(Type t) {
                          return types.boxedTypeOrType(t);
                      }
                  };


      It would be better if this class was refactored to take advantage of lambda expressions; two options are available:

      1) Make Mapping a functional interface and get rid of the (unused) name field
      2) Tweak the Mapping constructor so as to take a Function<Type, Type>

      Let's see how the above code snipped would change in both options:

      1) functional interface

                  Mapping boxMap = t -> types.boxedTypeOrType(t);

      2) lambda-friendly constructor:

                 Mapping boxMap = new Mapping("boxMap", t -> types.boxedTypeOrType(t));



            Unassigned Unassigned
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: