R
Rhino
I am currrently trying to "genericize" some of my older classes but I'm
having trouble with this simple class:
================================================================
public class IntRange extends TreeSet {
public IntRange(int firstInt, int secondInt) {
add(new Integer(firstInt));
add(new Integer(secondInt));
}
public IntRange(int[] intRange) {
if (intRange.length != 2) {
throw new IllegalArgumentException("The IntRange array must have
exactly two values.");
}
add(new Integer(intRange[0]));
add(new Integer(intRange[1]));
}
public boolean between(int input) {
if (input >= ((Integer) first()).intValue() && input <= ((Integer)
last()).intValue())
return (true);
else
return (false);
}
public int[] getValues() {
int[] values = new int[2];
values[0] = ((Integer) first()).intValue();
values[1] = ((Integer) last()).intValue();
return values;
}
}
================================================================
Can anyone tell me how to change the add() lines in the constructors to make
the compiler accept them? I thought that changing "public class IntRange
extends TreeSet" to "public class IntRange <Integer> extends TreeSet" might
solve all of my compiler warnings but it didn't; I'm not sure why. Could
someone explain what I _should_ do?
Frankly, I found the article on generics in the API pretty unhelpful in
getting beyond the most basic ideas. Can anyone point me to an article or
tutorial that explains these things more clearly? Then maybe I can
"genericize" the rest of my code on my own....
having trouble with this simple class:
================================================================
public class IntRange extends TreeSet {
public IntRange(int firstInt, int secondInt) {
add(new Integer(firstInt));
add(new Integer(secondInt));
}
public IntRange(int[] intRange) {
if (intRange.length != 2) {
throw new IllegalArgumentException("The IntRange array must have
exactly two values.");
}
add(new Integer(intRange[0]));
add(new Integer(intRange[1]));
}
public boolean between(int input) {
if (input >= ((Integer) first()).intValue() && input <= ((Integer)
last()).intValue())
return (true);
else
return (false);
}
public int[] getValues() {
int[] values = new int[2];
values[0] = ((Integer) first()).intValue();
values[1] = ((Integer) last()).intValue();
return values;
}
}
================================================================
Can anyone tell me how to change the add() lines in the constructors to make
the compiler accept them? I thought that changing "public class IntRange
extends TreeSet" to "public class IntRange <Integer> extends TreeSet" might
solve all of my compiler warnings but it didn't; I'm not sure why. Could
someone explain what I _should_ do?
Frankly, I found the article on generics in the API pretty unhelpful in
getting beyond the most basic ideas. Can anyone point me to an article or
tutorial that explains these things more clearly? Then maybe I can
"genericize" the rest of my code on my own....