-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
None
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));
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));