-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
6
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
Please allow codes that are similar in the use of Generics to the following to work:
<T extends InputStream> Map<Class<T>, T> map = new HashMap<Class<T>, T>();
FileInputStream FIS = ...;
ObjectInputStream OIS = ...;
map.add(FIS.getClass(), FIS);
map.add(ObjectInputStream.class, OIS);
map.add(FIS.class, OIS); // <-- nope, I don't like that!
JUSTIFICATION :
This slightly more advanced rule with Generics would add value and extends the uses of Collection Classes and other similar cases, providing useful compile-time type-checking as Generics have been. The feature requested is also compatible with type-erasure so it would have a minimal impact of the language syntax and structure in terms of backward compatibility.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
<T extends InputStream> Map<Class<T>, T> map = new HashMap<Class<T>, T>();
FileInputStream FIS = ...;
ObjectInputStream OIS = ...;
map.add(FIS.getClass(), FIS);
map.add(ObjectInputStream.class, OIS);
map.add(FIS.class, OIS); // <-- nope, I don't like that!
ACTUAL -
Map<Class<? extends InputStream>, ? extends InputStream> map = new HashMap<Class<? extends InputStream>, ? extends InputStream>();
FileInputStream FIS = ...;
ObjectInputStream OIS = ...;
map.add(FIS.getClass(), FIS);
map.add(ObjectInputStream.class, OIS);
map.add(FIS.class, OIS); // well, you'll have to try hard to spot this yourself
###@###.### 2005-04-04 06:06:14 GMT
The submitter has provided additional details:
Enable "declaration" of generic type variables other than just at class and
method declaration levels. In other words, in addition to:
- public class C<T extends A> ...
- public <T extends B> boolean M(...
It would be helpful to have, for instance:
1) Inline type variable declaration
<T extends Expression> Map<Class<T>, Comparator<T>> map = ...;
// The following lines would be alright
map.add(Rational.class, SomeRationalComparator);
map.add(Complex.class, SomeComplexComparator);
// The following line would generate a compile-time error
map.add(Rational.class, SomeComplexComparator);
Which is useful for:
<T extends Expression> Comparator<T> getComparator(Class<T> clazz) {
return map.get(clazz);
}
2) Type variable declaration within scopes
...
{
<T extends Expression>
...
}
----------------------------------------------------------------------
Evidently, if case (2) is implemented then case (1) is done as well;
although at present I couldn't find a convincing use case for case (2) yet -
I shall get back to you as soon as the idea hits me.
###@###.### 2005-04-12 06:23:28 GMT
Please allow codes that are similar in the use of Generics to the following to work:
<T extends InputStream> Map<Class<T>, T> map = new HashMap<Class<T>, T>();
FileInputStream FIS = ...;
ObjectInputStream OIS = ...;
map.add(FIS.getClass(), FIS);
map.add(ObjectInputStream.class, OIS);
map.add(FIS.class, OIS); // <-- nope, I don't like that!
JUSTIFICATION :
This slightly more advanced rule with Generics would add value and extends the uses of Collection Classes and other similar cases, providing useful compile-time type-checking as Generics have been. The feature requested is also compatible with type-erasure so it would have a minimal impact of the language syntax and structure in terms of backward compatibility.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
<T extends InputStream> Map<Class<T>, T> map = new HashMap<Class<T>, T>();
FileInputStream FIS = ...;
ObjectInputStream OIS = ...;
map.add(FIS.getClass(), FIS);
map.add(ObjectInputStream.class, OIS);
map.add(FIS.class, OIS); // <-- nope, I don't like that!
ACTUAL -
Map<Class<? extends InputStream>, ? extends InputStream> map = new HashMap<Class<? extends InputStream>, ? extends InputStream>();
FileInputStream FIS = ...;
ObjectInputStream OIS = ...;
map.add(FIS.getClass(), FIS);
map.add(ObjectInputStream.class, OIS);
map.add(FIS.class, OIS); // well, you'll have to try hard to spot this yourself
###@###.### 2005-04-04 06:06:14 GMT
The submitter has provided additional details:
Enable "declaration" of generic type variables other than just at class and
method declaration levels. In other words, in addition to:
- public class C<T extends A> ...
- public <T extends B> boolean M(...
It would be helpful to have, for instance:
1) Inline type variable declaration
<T extends Expression> Map<Class<T>, Comparator<T>> map = ...;
// The following lines would be alright
map.add(Rational.class, SomeRationalComparator);
map.add(Complex.class, SomeComplexComparator);
// The following line would generate a compile-time error
map.add(Rational.class, SomeComplexComparator);
Which is useful for:
<T extends Expression> Comparator<T> getComparator(Class<T> clazz) {
return map.get(clazz);
}
2) Type variable declaration within scopes
...
{
<T extends Expression>
...
}
----------------------------------------------------------------------
Evidently, if case (2) is implemented then case (1) is done as well;
although at present I couldn't find a convincing use case for case (2) yet -
I shall get back to you as soon as the idea hits me.
###@###.### 2005-04-12 06:23:28 GMT