Generics
Next one.
This code cannot be compiled (with error message "you cannot use built-in array for generics type") even if the commented out "Integer" version works.
I really love new Swing L&F "Ocean", and likes extended for-loop, but I think Generics might be too early for JDK1.5. It's very confusing. And once it's introduced, we cannot go back.
import java.util.*;
class Hoge> implements Comparable>
{
private T _value;
public Hoge(T value)
{
_value = value;
}
public int compareTo(Hoge h)
{
return _value.compareTo(h._value);
}
public String toString()
{
return String.valueOf(_value);
}
}
class MeApp
{
public static void main(String[] args)
{
Hoge[] a = new Hoge[] {
new Hoge(4),
new Hoge(1),
new Hoge(3)
};
/*
Integer[] a = new Integer[] {
new Integer(4),
new Integer(1),
new Integer(3)
};
*/
Arrays.sort(a);
for (Hoge x : a)
{
System.out.println(x);
}
/*
for (Integer x : a)
{
System.out.println(x);
}
}
*/
}
Posted by: whiterabbit on February 09, 2004 at 09:12 PM