-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
1.4.2
-
x86
-
windows_xp
Name: jl125535 Date: 02/27/2004
A DESCRIPTION OF THE REQUEST :
Although generics are great, a simple method or two could provide a very useful functionality without much additional cost.
Providing users with a means to get the common ancestor class of all elements contained in a Set would be useful as a quick and efficient replacement for users who don't want to reimplement their code with 1.5 generics and at the same time get the benefit of knowing what their set is really made of. On a separate track, it is always useful, generics or not, to know what you set really contains.
JUSTIFICATION :
The alternative is to write a dirty hack in the code or provide an EnhancedSet and reimplement all the corresponding features of Vector, HashSet...
This enhancement would nicely fit in the Set class.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Getting the common ancestor Class of all the element's class contained in a Set.
ACTUAL -
The feature is currently not supported. This is the "tomatoes" problem.
---------- BEGIN SOURCE ----------
//gets the class shared by all
public Class getCommonClass() {
Iterator iterator;
Class tempClass;
Class result;
if (set.size()>1) {
iterator = set.iterator();
result = iterator.next().getClass();
while (iterator.hasNext()) {
tempClass = iterator.next().getClass();
while (!(result instanceof tempClass)) {
result = result.superclass();
}
}
} else {
if (set.size()==0) {
result=null;
} else {
result=set.iterator().next().getClass();
}
}
return result;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See the above code.
(Incident Review ID: 240516)
======================================================================
A DESCRIPTION OF THE REQUEST :
Although generics are great, a simple method or two could provide a very useful functionality without much additional cost.
Providing users with a means to get the common ancestor class of all elements contained in a Set would be useful as a quick and efficient replacement for users who don't want to reimplement their code with 1.5 generics and at the same time get the benefit of knowing what their set is really made of. On a separate track, it is always useful, generics or not, to know what you set really contains.
JUSTIFICATION :
The alternative is to write a dirty hack in the code or provide an EnhancedSet and reimplement all the corresponding features of Vector, HashSet...
This enhancement would nicely fit in the Set class.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Getting the common ancestor Class of all the element's class contained in a Set.
ACTUAL -
The feature is currently not supported. This is the "tomatoes" problem.
---------- BEGIN SOURCE ----------
//gets the class shared by all
public Class getCommonClass() {
Iterator iterator;
Class tempClass;
Class result;
if (set.size()>1) {
iterator = set.iterator();
result = iterator.next().getClass();
while (iterator.hasNext()) {
tempClass = iterator.next().getClass();
while (!(result instanceof tempClass)) {
result = result.superclass();
}
}
} else {
if (set.size()==0) {
result=null;
} else {
result=set.iterator().next().getClass();
}
}
return result;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See the above code.
(Incident Review ID: 240516)
======================================================================