Updates:
Status: Started
Comment #17 on issue 495 by tudor.gi...(a)gmail.com: Parametrized Types -
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495
So, now we have ParameterizableClass having parameters as a collection of
strings. The problem is that in this way we cannot model the below case.
First, T should actually be some sort of a local type that can be used as
declaredType.
Second, T should also be allowed to inherit.
What a mess. Any ideas of how to model that?
----EXAMPLE----
interface MinMax<T extends Comparable<T>> {
T min();
T max();
}
class MyClass<T extends Comparable<T>> implements MinMax<T> {
T[] vals;
MyClass(T[] o) { vals = o; }
public T min() {
T v = vals[0];
for(int i=1; i < vals.length; i++)
if(vals[i].compareTo(v) < 0) v = vals[i];
return v;
}
public T max() {
T v = vals[0];
for(int i=1; i < vals.length; i++)
if(vals[i].compareTo(v) > 0) v = vals[i];
return v;
}
}
public class GenIFDemo {
public static void main(String args[]) {
Integer inums[] = {3, 6, 2, 8, 6 };
Character chs[] = {'b', 'r', 'p', 'w' };
MyClass<Integer> iob = new MyClass<Integer>(inums);
MyClass<Character> cob = new MyClass<Character>(chs);
System.out.println("Max value in inums: " + iob.max());
System.out.println("Min value in inums: " + iob.min());
System.out.println("Max value in chs: " + cob.max());
System.out.println("Min value in chs: " + cob.min());
}
}