-
Enhancement
-
Resolution: Other
-
P4
-
None
-
None
-
None
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>;
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>;
- duplicates
-
JDK-4194542 class name aliasing
-
- Closed
-
-
JDK-4984992 Alpha Feedback: Provide alias statement
-
- Closed
-
-
JDK-6368076 Implicit typing of references via 'auto' keyword like upcoming C++ feature
-
- Closed
-
- relates to
-
JDK-6840638 Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
-
- Closed
-
-
JDK-6368038 RFE subtyping final classes such as String, or Long to create compile time types
-
- Closed
-
-
JDK-6220689 Type arguments for a class shall be inferred on constructor invocation
-
- Closed
-
(1 relates to)