GenaralCompatator
类如下 private static class GenaralCompatator
implements Comparator
{ private String methodName = null;
private int asc = 1; public GenaralCompatator(String methodName, boolean asc)
{
this.methodName = methodName;
if (!asc)
{
this.asc = -1;
}
} public GenaralCompatator(String methodName, String compType)
{
this(methodName, true);
} public int compare(Object o1, Object o2)
{ int returnValue = 0;
try
{
java.lang.reflect.Method method = o1.getClass().getMethod(methodName, null); Object f1 = method.invoke(o1, null);
Object f2 = method.invoke(o2, null); method = f1.getClass().getMethod("compareTo", new Class[]
{f1.getClass()});
Object returnObj = method.invoke(f1, new Object[]
{f2});
Integer toInteger = (Integer) (returnObj);
returnValue = asc * (toInteger.intValue());
}
catch (Exception e)
{
e.printStackTrace();
}
return returnValue;
}
}
类如下 private static class GenaralCompatator
implements Comparator
{ private String methodName = null;
private int asc = 1; public GenaralCompatator(String methodName, boolean asc)
{
this.methodName = methodName;
if (!asc)
{
this.asc = -1;
}
} public GenaralCompatator(String methodName, String compType)
{
this(methodName, true);
} public int compare(Object o1, Object o2)
{ int returnValue = 0;
try
{
java.lang.reflect.Method method = o1.getClass().getMethod(methodName, null); Object f1 = method.invoke(o1, null);
Object f2 = method.invoke(o2, null); method = f1.getClass().getMethod("compareTo", new Class[]
{f1.getClass()});
Object returnObj = method.invoke(f1, new Object[]
{f2});
Integer toInteger = (Integer) (returnObj);
returnValue = asc * (toInteger.intValue());
}
catch (Exception e)
{
e.printStackTrace();
}
return returnValue;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货