1.7 javac is apparently more perceptive than ejc when it comes to warning about
raw type usage. I'm surprised that the Eclipse code hygienist failed to catch
these. Also had to be slightly more blatant in a few places where we're
subverting the generics type system because the 1.7 javac is less tolerant of
the fast and loose.
For future reference, that usually means first assigning a reference to a
wildcard and then casting that to what you want:
Foo<?> fc = someFooWithCrazyAssParameters;
@SuppressWarnings("unchecked") Foo<Object> fo = (Foo<Object>)fc;
instead of just:
@SuppressWarnings("unchecked") Foo<Object> fo =
(Foo<Object>)someFooWithCrazyAssParameters;
because javac won't let you do casts that are inconvertible and it's smarter
about what sort of generic types are convertible to one another.
Hopefully this future reference won't be needed because we won't be needing to
subvert the type system. But when reflection is involved, it's hard not to end
up doing a bit of the old Father Knows Best.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2756 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -448,7 +448,7 @@ public class Table<T>
|
||||
fMask = new FieldMask(fields);
|
||||
|
||||
try {
|
||||
constructor = _rowClass.getDeclaredConstructor(new Class[0]);
|
||||
constructor = _rowClass.getDeclaredConstructor(new Class<?>[0]);
|
||||
setBypass.invoke(constructor, bypassFlag);
|
||||
} catch(Exception ex) {}
|
||||
|
||||
@@ -571,7 +571,7 @@ public class Table<T>
|
||||
|
||||
try {
|
||||
fd.constructor =
|
||||
fieldClass.getDeclaredConstructor(new Class[0]);
|
||||
fieldClass.getDeclaredConstructor(new Class<?>[0]);
|
||||
setBypass.invoke(fd.constructor, bypassFlag);
|
||||
} catch(Exception ex) {}
|
||||
|
||||
|
||||
@@ -236,9 +236,10 @@ public class TableSorter extends AbstractTableModel {
|
||||
return comparator;
|
||||
}
|
||||
if (Comparable.class.isAssignableFrom(columnType)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Comparator<Object> c = Comparators.COMPARABLE;
|
||||
return c;
|
||||
// this is messy, but reflection and generics don't play nice
|
||||
Comparator<?> c = Comparators.COMPARABLE;
|
||||
@SuppressWarnings("unchecked") Comparator<Object> co = (Comparator<Object>)c;
|
||||
return co;
|
||||
}
|
||||
return Comparators.LEXICAL_CASE_INSENSITIVE;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class TaskMaster
|
||||
public Object invoke () throws Exception
|
||||
{
|
||||
// look up the named method on the source object and invoke it
|
||||
Method meth = _source.getClass().getMethod(_name, (Class[]) null);
|
||||
Method meth = _source.getClass().getMethod(_name, (Class<?>[]) null);
|
||||
meth.setAccessible(true);
|
||||
return meth.invoke(_source, (Object[]) null);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class ClassUtil
|
||||
{
|
||||
Class<?>[] argTypes = null;
|
||||
if (args != null) {
|
||||
argTypes = new Class[args.length];
|
||||
argTypes = new Class<?>[args.length];
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
argTypes[i] = (args[i] == null) ? Void.TYPE : args[i].getClass();
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@ public class Comparators
|
||||
};
|
||||
|
||||
/**
|
||||
* A comparator that compares {@link Comparable} instances.
|
||||
* A comparator that compares {@link Comparable<Object>} instances.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final Comparator COMPARABLE = new Comparator() {
|
||||
public int compare (Object o1, Object o2)
|
||||
public static final Comparator<Comparable<Object>> COMPARABLE =
|
||||
new Comparator<Comparable<Object>>() {
|
||||
public int compare (Comparable<Object> o1, Comparable<Object> o2)
|
||||
{
|
||||
if (o1 == o2) { // catches null == null
|
||||
return 0;
|
||||
@@ -60,7 +60,7 @@ public class Comparators
|
||||
} else if (o2 == null) {
|
||||
return -1;
|
||||
}
|
||||
return ((Comparable)o1).compareTo(o2); // null-free
|
||||
return o1.compareTo(o2); // null-free
|
||||
}
|
||||
};
|
||||
|
||||
@@ -72,10 +72,12 @@ public class Comparators
|
||||
* Comparator<Integer> = Comparators.comparable();
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final <T extends Comparable> Comparator<T> comparable ()
|
||||
// we can't do the "more correct" <T extends Comparable<? super T>> here as that causes other
|
||||
// code to freak out; I don't entirely understand why
|
||||
public static final <T extends Comparable<?>> Comparator<T> comparable ()
|
||||
{
|
||||
return COMPARABLE;
|
||||
@SuppressWarnings("unchecked") Comparator<T> comp = (Comparator<T>)COMPARABLE;
|
||||
return comp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,12 +125,13 @@ public class CountHashMap<K> extends HashMap<K, int[]>
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<Map.Entry<K, int[]>> entrySet ()
|
||||
{
|
||||
// a giant mess of hoop-jumpery so that we can convert each Map.Entry returned by the
|
||||
// iterator to be a CountEntryImpl
|
||||
return new CountEntrySet(super.entrySet());
|
||||
Set<?> eset = new CountEntrySet<K>(super.entrySet());
|
||||
@SuppressWarnings("unchecked") Set<Map.Entry<K, int[]>> r = (Set<Map.Entry<K, int[]>>)eset;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -517,7 +517,7 @@ public class HashIntMap<V> extends AbstractMap<Integer,V>
|
||||
|
||||
protected Record<V>[] createBuckets (int size)
|
||||
{
|
||||
@SuppressWarnings("unchecked") Record<V>[] recs = new Record[size];
|
||||
@SuppressWarnings("unchecked") Record<V>[] recs = (Record<V>[])new Record<?>[size];
|
||||
return recs;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class MethodFinder
|
||||
maybeLoadConstructors();
|
||||
|
||||
if (parameterTypes == null) {
|
||||
parameterTypes = new Class[0];
|
||||
parameterTypes = new Class<?>[0];
|
||||
}
|
||||
|
||||
return (Constructor<?>)findMemberIn(_ctorList, parameterTypes);
|
||||
@@ -135,7 +135,7 @@ public class MethodFinder
|
||||
}
|
||||
|
||||
if (parameterTypes == null) {
|
||||
parameterTypes = new Class[0];
|
||||
parameterTypes = new Class<?>[0];
|
||||
}
|
||||
|
||||
return (Method)findMemberIn(methodList, parameterTypes);
|
||||
|
||||
@@ -707,7 +707,7 @@ public class StringUtil
|
||||
buf.append(fields[i].getName()).append("=");
|
||||
try {
|
||||
try {
|
||||
Method meth = clazz.getMethod(fields[i].getName() + "ToString", new Class[0]);
|
||||
Method meth = clazz.getMethod(fields[i].getName() + "ToString", new Class<?>[0]);
|
||||
buf.append(meth.invoke(object, (Object[]) null));
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
toString(buf, fields[i].get(object));
|
||||
|
||||
@@ -418,6 +418,7 @@ public class DispatcherServlet extends HttpServlet
|
||||
/**
|
||||
* Called when a method throws an exception during template evaluation.
|
||||
*/
|
||||
@Override @SuppressWarnings("rawtypes") // our super class declares a bare Class
|
||||
public Object methodException (Class clazz, String method, Exception e)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user