I’m getting the following error with some Java code I’ve written:
internal error; cannot instantiate () at <anonymous <any>> to ()
What I’ve done is created an interface similar to java.lang.Comparable, which is defined as follows:
public interface Comparable<T>
{
public int compareTo(T o);
}
My interface is:
public interface CustomComparable<T>
{
public int compare(T a, T b);
}
If I try to create an anonymous inner class using Comparable, it’s fine…
public void someThing()
{
Comparable<Object> o = new Comparable<Object>()
{
public int compareTo(Object o)
{
// ...
}
};
}
With my interface I get the error outlined above. Why? Is java.lang.Comparable treated specially?
public void someThing()
{
CustomComparable<Object> o = new CustomComparable<Object>()
{
public int compare(Object a, Object b)
{
// ...
}
};
}
I’m using Java 1.6u21 and NetBeans 6.9.1.
It looks like you want to use a
Comparator<T>and not aComparable<T>— the interface already exists.