remove some warning
This commit is contained in:
parent
07952df53a
commit
3e17d66d25
@ -31,14 +31,14 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class Cocos2dxReflectionHelper {
|
public class Cocos2dxReflectionHelper {
|
||||||
public static <T> T getConstantValue(final Class aClass, final String constantName) {
|
public static <T> T getConstantValue(final Class<?> aClass, final String constantName) {
|
||||||
try {
|
try {
|
||||||
return (T)aClass.getDeclaredField(constantName).get(null);
|
return (T)aClass.getDeclaredField(constantName).get(null);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
Log.e("error", "can not find " + constantName + " in " + aClass.getName());
|
Log.e("error", "can not find " + constantName + " in " + aClass.getName());
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException e) {
|
catch (IllegalAccessException e) {
|
||||||
Log.e("error", constantName + " is not accessable");
|
Log.e("error", constantName + " is not accessible");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
Log.e("error", "arguments error when get " + constantName);
|
Log.e("error", "arguments error when get " + constantName);
|
||||||
@ -50,13 +50,13 @@ public class Cocos2dxReflectionHelper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T invokeInstanceMethod(final Object instance, final String methodName,
|
public static <T> void invokeInstanceMethod(final Object instance, final String methodName,
|
||||||
final Class[] parameterTypes, final Object[] parameters) {
|
final Class<?>[] parameterTypes, final Object[] parameters) {
|
||||||
|
|
||||||
final Class aClass = instance.getClass();
|
final Class<?> aClass = instance.getClass();
|
||||||
try {
|
try {
|
||||||
final Method method = aClass.getMethod(methodName, parameterTypes);
|
final Method method = aClass.getMethod(methodName, parameterTypes);
|
||||||
return (T)method.invoke(instance, parameters);
|
method.invoke(instance, parameters);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Log.e("error", "can not find " + methodName + " in " + aClass.getName());
|
Log.e("error", "can not find " + methodName + " in " + aClass.getName());
|
||||||
}
|
}
|
||||||
@ -70,6 +70,5 @@ public class Cocos2dxReflectionHelper {
|
|||||||
Log.e("error", "an exception was thrown by the invoked method when invoking " + methodName);
|
Log.e("error", "an exception was thrown by the invoked method when invoking " + methodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user