本文整理了Java中java.lang.Class.equals()
方法的一些代码示例,展示了Class.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.equals()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:equals
暂无
代码示例来源:origin: com.jtransc/jtransc-rt
private static int deepHashCodeElement(Object element) {
Class<?> cl;
if (element == null) return 0;
cl = element.getClass().getComponentType();
if (cl == null) return element.hashCode();
if (!cl.isPrimitive()) return deepHashCode((Object[]) element);
if (cl.equals(int.class)) return hashCode((int[]) element);
if (cl.equals(char.class)) return hashCode((char[]) element);
if (cl.equals(boolean.class)) return hashCode((boolean[]) element);
if (cl.equals(byte.class)) return hashCode((byte[]) element);
if (cl.equals(long.class)) return hashCode((long[]) element);
if (cl.equals(float.class)) return hashCode((float[]) element);
if (cl.equals(double.class)) return hashCode((double[]) element);
return hashCode((short[]) element);
}
代码示例来源:origin: dragome/dragome-sdk
private boolean isTestMethod(Method m)
{
org.junit.Test annotation = m.getAnnotation(org.junit.Test.class);
return m.getParameterTypes().length == 0 && annotation != null && m.getReturnType().equals(Void.TYPE);
}
}
代码示例来源:origin: dragome/dragome-sdk
private boolean isSameClass()
{
if (!(parameters[0] instanceof Object))
return false;
Class<? extends Object> type= parameters[0].getClass();
if (Proxy.isProxyClass(type))
{
InvocationHandler invocationHandler= Proxy.getInvocationHandler(parameters[0]);
if (invocationHandler instanceof InvocationHandlerForLambdas)
type= ((InvocationHandlerForLambdas) invocationHandler).returnType;
else
return class1.isAssignableFrom(type);
}
return type.equals(class1);
}
代码示例来源:origin: com.jtransc/jtransc-rt
@JTranscSync
static private boolean Arrays_equals(Class<?>[] l, Class<?>[] r) {
if (l.length != r.length) return false;
for (int n = 0; n < l.length; n++) {
if (!l[n].equals(r[n])) return false;
}
return true;
}
代码示例来源:origin: dragome/dragome-sdk
private Object convertResult(Class<?> type, String annotationValue) throws java.lang.ClassNotFoundException
{
if (type.isArray())
{
List<Object> result= new ArrayList<>();
Class<?> componentType= type.getComponentType();
String[] items= annotationValue.replace("{", "").replace("}", "").split(",");
for (String item : items)
{
Object convertResult= convertResult(componentType, item);
result.add(convertResult);
}
return result.toArray();
}
else if (type.equals(Boolean.class) || type.equals(boolean.class))
return Boolean.parseBoolean(annotationValue);
else if (type.equals(Class.class))
return Class.forName(annotationValue.substring(1, annotationValue.length() - 1).replace("/", "."));
else if (type.equals(Integer.class) || type.equals(int.class))
return Integer.parseInt(annotationValue);
else if (type.equals(Double.class) || type.equals(double.class))
return Double.parseDouble(annotationValue);
else
return annotationValue;
}
代码示例来源:origin: dragome/dragome-sdk
public Object[] boxParameters(Object[] args)
{
Class<?>[] parameterTypes= getParameterTypes();
for (int i= 0; i < parameterTypes.length; i++)
{
if (parameterTypes[i].isPrimitive())
{
ScriptHelper.put("primitiveValue", args[i], null);
String stringValue= (String) ScriptHelper.eval("primitiveValue.toString()", this);
if (parameterTypes[i].equals(int.class))
args[i]= new Integer(stringValue);
else if (parameterTypes[i].equals(long.class))
args[i]= new Long(stringValue);
else if (parameterTypes[i].equals(float.class))
args[i]= new Float(stringValue);
else if (parameterTypes[i].equals(double.class))
args[i]= new Double(stringValue);
else if (parameterTypes[i].equals(short.class))
args[i]= new Short(stringValue);
else if (parameterTypes[i].equals(char.class))
args[i]= new Character(stringValue.charAt(0));
else if (parameterTypes[i].equals(byte.class))
args[i]= new Byte(stringValue);
else if (parameterTypes[i].equals(boolean.class))
args[i]= new Boolean(stringValue);
}
}
return args;
}
代码示例来源:origin: com.jtransc/jtransc-rt
if (cl1.equals(int.class)) {
return equals((int[]) e1, (int[]) e2);
if (cl1.equals(char.class)) {
return equals((char[]) e1, (char[]) e2);
if (cl1.equals(boolean.class)) {
return equals((boolean[]) e1, (boolean[]) e2);
if (cl1.equals(byte.class)) {
return equals((byte[]) e1, (byte[]) e2);
if (cl1.equals(long.class)) {
return equals((long[]) e1, (long[]) e2);
if (cl1.equals(float.class)) {
return equals((float[]) e1, (float[]) e2);
if (cl1.equals(double.class)) {
return equals((double[]) e1, (double[]) e2);
代码示例来源:origin: dragome/dragome-sdk
/**
* Determines if the class or interface represented by this Class object is either the same as, or is a
* superclass or superinterface of, the class or interface represented by the specified Class parameter.
*/
public boolean isAssignableFrom(Class<?> otherClass)
{
Class<?>[] interfaces= getInterfaces();
if (otherClass == null)
throw new NullPointerException();
if (otherClass.isInterface() && Object.class.equals(this))
return true;
ScriptHelper.put("otherClass", otherClass, this);
return ScriptHelper.evalBoolean("dragomeJs.isInstanceof(otherClass.$$$nativeClass___java_lang_Object, this.$$$nativeClass___java_lang_Object)", this);
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul.mini
public static Method findMethod(
Class<?> clazz, String name, Class<?>... parameterTypes
) {
name = name.replace("_", "_1");
Object[] data = findMethodData(clazz, name + "__", false);
BIG: for (int i = 0; i < data.length; i += 3) {
String sig = ((String) data[i]).substring(name.length() + 2);
Class<?> cls = (Class<?>) data[i + 2];
Method tmp = INSTANCE.create(cls, name, data[i + 1], sig);
Class<?>[] tmpParms = tmp.getParameterTypes();
if (parameterTypes.length != tmpParms.length) {
continue;
}
for (int j = 0; j < tmpParms.length; j++) {
if (!parameterTypes[j].equals(tmpParms[j])) {
continue BIG;
}
}
return tmp;
}
return null;
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul.mini
public static Constructor findConstructor(
Class<?> clazz, Class<?>... parameterTypes) {
Object[] data = findMethodData(clazz, "cons__", true);
BIG: for (int i = 0; i < data.length; i += 3) {
String sig = ((String) data[i]).substring(6);
Class<?> cls = (Class<?>) data[i + 2];
Constructor tmp = INSTANCE.create(cls, data[i + 1], sig);
Class<?>[] tmpParms = tmp.getParameterTypes();
if (parameterTypes.length != tmpParms.length) {
continue;
}
for (int j = 0; j < tmpParms.length; j++) {
if (!parameterTypes[j].equals(tmpParms[j])) {
continue BIG;
}
}
return tmp;
}
return null;
}
代码示例来源:origin: dragome/dragome-sdk
if (currentReturnType.equals(Boolean.class))
result= result instanceof Boolean ? result : (ScriptHelper.evalBoolean("result", null) ? Boolean.TRUE : Boolean.FALSE);
else if (currentReturnType.equals(Integer.class))
result= Integer.parseInt(ScriptHelper.evalInt("result", null) + "");
else if (currentReturnType.equals(Long.class))
result= Long.parseLong(ScriptHelper.evalInt("result", null) + "");
else if (currentReturnType.equals(Short.class))
result= Short.parseShort(ScriptHelper.evalInt("result", null) + "");
else if (currentReturnType.equals(Float.class))
result= Float.parseFloat(ScriptHelper.evalFloat("result", null) + "");
else if (currentReturnType.equals(Double.class))
result= Double.parseDouble(ScriptHelper.evalDouble("result", null) + "");
else if (currentReturnType.equals(Byte.class))
result= Byte.valueOf((byte) ScriptHelper.evalChar("result", null));
else if (currentReturnType.equals(Character.class))
result= Character.valueOf((ScriptHelper.eval("result", null) + "").charAt(0));
代码示例来源:origin: jtulach/bck2brwsr
public static Method findMethod(
Class<?> clazz, String name, Class<?>... parameterTypes
) {
name = name.replace("_", "_1");
Object[] data = findMethodData(clazz, name + "__", false);
BIG: for (int i = 0; i < data.length; i += 3) {
String sig = ((String) data[i]).substring(name.length() + 2);
Class<?> cls = (Class<?>) data[i + 2];
Method tmp = INSTANCE.create(cls, name, data[i + 1], sig);
Class<?>[] tmpParms = tmp.getParameterTypes();
if (parameterTypes.length != tmpParms.length) {
continue;
}
for (int j = 0; j < tmpParms.length; j++) {
if (!parameterTypes[j].equals(tmpParms[j])) {
continue BIG;
}
}
return tmp;
}
return null;
}
代码示例来源:origin: jtulach/bck2brwsr
public static Constructor findConstructor(
Class<?> clazz, Class<?>... parameterTypes) {
Object[] data = findMethodData(clazz, "cons__", true);
BIG: for (int i = 0; i < data.length; i += 3) {
String sig = ((String) data[i]).substring(6);
Class<?> cls = (Class<?>) data[i + 2];
Constructor tmp = INSTANCE.create(cls, data[i + 1], sig);
Class<?>[] tmpParms = tmp.getParameterTypes();
if (parameterTypes.length != tmpParms.length) {
continue;
}
for (int j = 0; j < tmpParms.length; j++) {
if (!parameterTypes[j].equals(tmpParms[j])) {
continue BIG;
}
}
return tmp;
}
return null;
}
代码示例来源:origin: com.jtransc/jtransc-rt
if (elemElemClass.isPrimitive()) {
if (boolean.class.equals(elemElemClass)) {
sb.append(toString((boolean[]) elem));
} else if (byte.class.equals(elemElemClass)) {
sb.append(toString((byte[]) elem));
} else if (char.class.equals(elemElemClass)) {
sb.append(toString((char[]) elem));
} else if (double.class.equals(elemElemClass)) {
sb.append(toString((double[]) elem));
} else if (float.class.equals(elemElemClass)) {
sb.append(toString((float[]) elem));
} else if (int.class.equals(elemElemClass)) {
sb.append(toString((int[]) elem));
} else if (long.class.equals(elemElemClass)) {
sb.append(toString((long[]) elem));
} else if (short.class.equals(elemElemClass)) {
sb.append(toString((short[]) elem));
} else {
代码示例来源:origin: dragome/dragome-sdk
if (type.equals(Integer.class))
return ScriptHelper.eval("intValue", null);
else if (type.equals(Boolean.class))
return ScriptHelper.eval("booleanValue", null);
else if (type.equals(Long.class))
return ScriptHelper.eval("longValue", null);
else if (type.equals(Short.class))
return ScriptHelper.eval("shortValue", null);
else if (type.equals(Byte.class))
return ScriptHelper.eval("byteValue", null);
else if (type.equals(Float.class))
return ScriptHelper.eval("floatValue", null);
else if (type.equals(Double.class))
else if (type.equals(Character.class))
代码示例来源:origin: dragome/dragome-sdk
public static <A extends Annotation> A getAnnotationInternal(Class<?> aClass, Class<A> annotationClass, String methodName, Integer parameterIndex, String fieldName)
{
List<AnnotationEntry> annotationEntries= new ArrayList<>(AnnotationsHelper.getAnnotationsByType(annotationClass).getEntries());
boolean annotationFound= false;
for (AnnotationEntry annotationEntry : annotationEntries)
if (annotationEntry.getType().equals(aClass))
{
String annotationKey= AnnotationInvocationHandler.getAnnotationKey(fieldName, parameterIndex, methodName, "");
if (annotationEntry.getAnnotationKey().startsWith(annotationKey) || (annotationKey == null && !annotationEntry.getAnnotationKey().contains("/")))
annotationFound= true;
}
if (!annotationFound)
return null;
A annotation= (A) Proxy.newProxyInstance(null, new Class[] { annotationClass }, new AnnotationInvocationHandler(aClass, annotationClass, methodName, parameterIndex, fieldName));
return annotation;
}
代码示例来源:origin: dragome/dragome-sdk
public Object invoke(Object proxy, Method method, Object[] args) throws java.lang.ClassNotFoundException
{
ScriptHelper.put("method", method, this);
String name= method.getName();
if (name.equals("toString"))
{
return clazz.toString();
}
else if (name.equals("annotationType"))
{
return annotationClass;
}
else
{
List<AnnotationEntry> annotationEntries= new ArrayList<>(AnnotationsHelper.getAnnotationsByType(annotationClass).getEntries());
for (AnnotationEntry annotationEntry : annotationEntries)
{
String key= getAnnotationKey(fieldName, parameterIndex, methodName, name);
if (annotationEntry.getType().equals(clazz) && annotationEntry.getAnnotationKey().startsWith(key))
{
java.lang.String annotationValue= annotationEntry.getAnnotationValue();
return convertResult(method.getReturnType(), annotationValue);
}
}
String result= (String) ScriptHelper.eval("this.$$$annotationClass___java_lang_Class.$$$nativeClass___java_lang_Object.$$members[method.$$$signature___java_lang_String].apply()", this);
return convertResult(method.getReturnType(), result);
}
}
内容来源于网络,如有侵权,请联系作者删除!