You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by il...@apache.org on 2019/09/03 09:23:56 UTC
[dubbo] branch master updated: simplifed and beautify code (#4921)
This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 3702887 simplifed and beautify code (#4921)
3702887 is described below
commit 370288799a72344b48723e80286acc2eb41164a1
Author: Licho <ch...@gmail.com>
AuthorDate: Tue Sep 3 17:23:51 2019 +0800
simplifed and beautify code (#4921)
* fix convertMethodConfig2AsyncInfo spelling error
* simplified code
* refact: simplified code
* feat: add unittest of JavaBeanSerializeUtilTest class
* feat: add unittest of JavaBeanSerializeUtilTest class
* refact: simplify and Beautify the code
* feat: add unittest of JavaBeanSerializeUtilTest class
* refact: simplify code
* refact: simplify code
* refact: simplify code
* refact: simplify code
* refact: simplify and beautify code
---
.../dubbo/common/extension/ExtensionLoader.java | 127 ++++++++--------
.../dubbo/common/utils/CompatibleTypeUtils.java | 106 +++++++++-----
.../apache/dubbo/common/utils/ReflectUtils.java | 160 ++++++++++++---------
.../dubbo/common/utils/ReflectUtilsTest.java | 16 ++-
4 files changed, 243 insertions(+), 166 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
index 03a5393..59c4514 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
@@ -469,21 +469,23 @@ public class ExtensionLoader<T> {
public T getAdaptiveExtension() {
Object instance = cachedAdaptiveInstance.get();
if (instance == null) {
- if (createAdaptiveInstanceError == null) {
- synchronized (cachedAdaptiveInstance) {
- instance = cachedAdaptiveInstance.get();
- if (instance == null) {
- try {
- instance = createAdaptiveExtension();
- cachedAdaptiveInstance.set(instance);
- } catch (Throwable t) {
- createAdaptiveInstanceError = t;
- throw new IllegalStateException("Failed to create adaptive instance: " + t.toString(), t);
- }
+ if (createAdaptiveInstanceError != null) {
+ throw new IllegalStateException("Failed to create adaptive instance: " +
+ createAdaptiveInstanceError.toString(),
+ createAdaptiveInstanceError);
+ }
+
+ synchronized (cachedAdaptiveInstance) {
+ instance = cachedAdaptiveInstance.get();
+ if (instance == null) {
+ try {
+ instance = createAdaptiveExtension();
+ cachedAdaptiveInstance.set(instance);
+ } catch (Throwable t) {
+ createAdaptiveInstanceError = t;
+ throw new IllegalStateException("Failed to create adaptive instance: " + t.toString(), t);
}
}
- } else {
- throw new IllegalStateException("Failed to create adaptive instance: " + createAdaptiveInstanceError.toString(), createAdaptiveInstanceError);
}
}
@@ -542,32 +544,38 @@ public class ExtensionLoader<T> {
}
private T injectExtension(T instance) {
+
+ if (objectFactory == null) {
+ return instance;
+ }
+
try {
- if (objectFactory != null) {
- for (Method method : instance.getClass().getMethods()) {
- if (isSetter(method)) {
- /**
- * Check {@link DisableInject} to see if we need auto injection for this property
- */
- if (method.getAnnotation(DisableInject.class) != null) {
- continue;
- }
- Class<?> pt = method.getParameterTypes()[0];
- if (ReflectUtils.isPrimitives(pt)) {
- continue;
- }
- try {
- String property = getSetterProperty(method);
- Object object = objectFactory.getExtension(pt, property);
- if (object != null) {
- method.invoke(instance, object);
- }
- } catch (Exception e) {
- logger.error("Failed to inject via method " + method.getName()
- + " of interface " + type.getName() + ": " + e.getMessage(), e);
- }
+ for (Method method : instance.getClass().getMethods()) {
+ if (!isSetter(method)) {
+ continue;
+ }
+ /**
+ * Check {@link DisableInject} to see if we need auto injection for this property
+ */
+ if (method.getAnnotation(DisableInject.class) != null) {
+ continue;
+ }
+ Class<?> pt = method.getParameterTypes()[0];
+ if (ReflectUtils.isPrimitives(pt)) {
+ continue;
+ }
+
+ try {
+ String property = getSetterProperty(method);
+ Object object = objectFactory.getExtension(pt, property);
+ if (object != null) {
+ method.invoke(instance, object);
}
+ } catch (Exception e) {
+ logger.error("Failed to inject via method " + method.getName()
+ + " of interface " + type.getName() + ": " + e.getMessage(), e);
}
+
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
@@ -623,7 +631,9 @@ public class ExtensionLoader<T> {
return classes;
}
- // synchronized in getExtensionClasses
+ /**
+ * synchronized in getExtensionClasses
+ * */
private Map<String, Class<?>> loadExtensionClasses() {
cacheDefaultExtensionName();
@@ -642,17 +652,19 @@ public class ExtensionLoader<T> {
*/
private void cacheDefaultExtensionName() {
final SPI defaultAnnotation = type.getAnnotation(SPI.class);
- if (defaultAnnotation != null) {
- String value = defaultAnnotation.value();
- if ((value = value.trim()).length() > 0) {
- String[] names = NAME_SEPARATOR.split(value);
- if (names.length > 1) {
- throw new IllegalStateException("More than 1 default extension name on extension " + type.getName()
- + ": " + Arrays.toString(names));
- }
- if (names.length == 1) {
- cachedDefaultName = names[0];
- }
+ if (defaultAnnotation == null) {
+ return;
+ }
+
+ String value = defaultAnnotation.value();
+ if ((value = value.trim()).length() > 0) {
+ String[] names = NAME_SEPARATOR.split(value);
+ if (names.length > 1) {
+ throw new IllegalStateException("More than 1 default extension name on extension " + type.getName()
+ + ": " + Arrays.toString(names));
+ }
+ if (names.length == 1) {
+ cachedDefaultName = names[0];
}
}
}
@@ -790,8 +802,8 @@ public class ExtensionLoader<T> {
cachedAdaptiveClass = clazz;
} else if (!cachedAdaptiveClass.equals(clazz)) {
throw new IllegalStateException("More than 1 adaptive class found: "
- + cachedAdaptiveClass.getClass().getName()
- + ", " + clazz.getClass().getName());
+ + cachedAdaptiveClass.getName()
+ + ", " + clazz.getName());
}
}
@@ -824,14 +836,15 @@ public class ExtensionLoader<T> {
@SuppressWarnings("deprecation")
private String findAnnotationName(Class<?> clazz) {
org.apache.dubbo.common.Extension extension = clazz.getAnnotation(org.apache.dubbo.common.Extension.class);
- if (extension == null) {
- String name = clazz.getSimpleName();
- if (name.endsWith(type.getSimpleName())) {
- name = name.substring(0, name.length() - type.getSimpleName().length());
- }
- return name.toLowerCase();
+ if (extension != null) {
+ return extension.value();
+ }
+
+ String name = clazz.getSimpleName();
+ if (name.endsWith(type.getSimpleName())) {
+ name = name.substring(0, name.length() - type.getSimpleName().length());
}
- return extension.value();
+ return name.toLowerCase();
}
@SuppressWarnings("unchecked")
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
index 5e1ba35..cce01c9 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
@@ -51,6 +51,7 @@ public class CompatibleTypeUtils {
if (value == null || type == null || type.isAssignableFrom(value.getClass())) {
return value;
}
+
if (value instanceof String) {
String string = (String) value;
if (char.class.equals(type) || Character.class.equals(type)) {
@@ -59,48 +60,64 @@ public class CompatibleTypeUtils {
" when convert String to char, the String MUST only 1 char.", string));
}
return string.charAt(0);
- } else if (type.isEnum()) {
+ }
+ if (type.isEnum()) {
return Enum.valueOf((Class<Enum>) type, string);
- } else if (type == BigInteger.class) {
+ }
+ if (type == BigInteger.class) {
return new BigInteger(string);
- } else if (type == BigDecimal.class) {
+ }
+ if (type == BigDecimal.class) {
return new BigDecimal(string);
- } else if (type == Short.class || type == short.class) {
+ }
+ if (type == Short.class || type == short.class) {
return new Short(string);
- } else if (type == Integer.class || type == int.class) {
+ }
+ if (type == Integer.class || type == int.class) {
return new Integer(string);
- } else if (type == Long.class || type == long.class) {
+ }
+ if (type == Long.class || type == long.class) {
return new Long(string);
- } else if (type == Double.class || type == double.class) {
+ }
+ if (type == Double.class || type == double.class) {
return new Double(string);
- } else if (type == Float.class || type == float.class) {
+ }
+ if (type == Float.class || type == float.class) {
return new Float(string);
- } else if (type == Byte.class || type == byte.class) {
+ }
+ if (type == Byte.class || type == byte.class) {
return new Byte(string);
- } else if (type == Boolean.class || type == boolean.class) {
- return new Boolean(string);
- } else if (type == Date.class || type == java.sql.Date.class || type == java.sql.Timestamp.class || type == java.sql.Time.class) {
+ }
+ if (type == Boolean.class || type == boolean.class) {
+ return Boolean.valueOf(string);
+ }
+ if (type == Date.class || type == java.sql.Date.class || type == java.sql.Timestamp.class
+ || type == java.sql.Time.class) {
try {
- Date date = new SimpleDateFormat(DATE_FORMAT).parse((String) value);
+ Date date = new SimpleDateFormat(DATE_FORMAT).parse(string);
if (type == java.sql.Date.class) {
return new java.sql.Date(date.getTime());
- } else if (type == java.sql.Timestamp.class) {
+ }
+ if (type == java.sql.Timestamp.class) {
return new java.sql.Timestamp(date.getTime());
- } else if (type == java.sql.Time.class) {
+ }
+ if (type == java.sql.Time.class) {
return new java.sql.Time(date.getTime());
- } else {
- return date;
}
+ return date;
} catch (ParseException e) {
- throw new IllegalStateException("Failed to parse date " + value + " by format " + DATE_FORMAT + ", cause: " + e.getMessage(), e);
+ throw new IllegalStateException("Failed to parse date " + value + " by format "
+ + DATE_FORMAT + ", cause: " + e.getMessage(), e);
}
- } else if (type == Class.class) {
+ }
+ if (type == Class.class) {
try {
- return ReflectUtils.name2class((String) value);
+ return ReflectUtils.name2class(string);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
}
- } else if (char[].class.equals(type)) {
+ }
+ if (char[].class.equals(type)) {
// Process string to char array for generic invoke
// See
// - https://github.com/apache/dubbo/issues/2003
@@ -109,30 +126,41 @@ public class CompatibleTypeUtils {
string.getChars(0, len, chars, 0);
return chars;
}
- } else if (value instanceof Number) {
+ }
+ if (value instanceof Number) {
Number number = (Number) value;
if (type == byte.class || type == Byte.class) {
return number.byteValue();
- } else if (type == short.class || type == Short.class) {
+ }
+ if (type == short.class || type == Short.class) {
return number.shortValue();
- } else if (type == int.class || type == Integer.class) {
+ }
+ if (type == int.class || type == Integer.class) {
return number.intValue();
- } else if (type == long.class || type == Long.class) {
+ }
+ if (type == long.class || type == Long.class) {
return number.longValue();
- } else if (type == float.class || type == Float.class) {
+ }
+ if (type == float.class || type == Float.class) {
return number.floatValue();
- } else if (type == double.class || type == Double.class) {
+ }
+ if (type == double.class || type == Double.class) {
return number.doubleValue();
- } else if (type == BigInteger.class) {
+ }
+ if (type == BigInteger.class) {
return BigInteger.valueOf(number.longValue());
- } else if (type == BigDecimal.class) {
+ }
+ if (type == BigDecimal.class) {
return BigDecimal.valueOf(number.doubleValue());
- } else if (type == Date.class) {
+ }
+ if (type == Date.class) {
return new Date(number.longValue());
- } else if (type == boolean.class || type == Boolean.class) {
+ }
+ if (type == boolean.class || type == Boolean.class) {
return 0 != number.intValue();
}
- } else if (value instanceof Collection) {
+ }
+ if (value instanceof Collection) {
Collection collection = (Collection) value;
if (type.isArray()) {
int length = collection.size();
@@ -142,19 +170,23 @@ public class CompatibleTypeUtils {
Array.set(array, i++, item);
}
return array;
- } else if (!type.isInterface()) {
+ }
+ if (!type.isInterface()) {
try {
Collection result = (Collection) type.newInstance();
result.addAll(collection);
return result;
- } catch (Throwable e) {
+ } catch (Throwable ignored) {
}
- } else if (type == List.class) {
+ }
+ if (type == List.class) {
return new ArrayList<Object>(collection);
- } else if (type == Set.class) {
+ }
+ if (type == Set.class) {
return new HashSet<Object>(collection);
}
- } else if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) {
+ }
+ if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) {
Collection collection;
if (!type.isInterface()) {
try {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java
index 0c1a13d..e2d89cb 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java
@@ -251,19 +251,24 @@ public final class ReflectUtils {
try {
ParameterizedType parameterizedType = ((ParameterizedType) cls.getGenericInterfaces()[0]);
Object genericClass = parameterizedType.getActualTypeArguments()[i];
- if (genericClass instanceof ParameterizedType) { // handle nested generic type
+
+ // handle nested generic type
+ if (genericClass instanceof ParameterizedType) {
return (Class<?>) ((ParameterizedType) genericClass).getRawType();
- } else if (genericClass instanceof GenericArrayType) { // handle array generic type
+ }
+
+ // handle array generic type
+ if (genericClass instanceof GenericArrayType) {
return (Class<?>) ((GenericArrayType) genericClass).getGenericComponentType();
- } else if (((Class) genericClass).isArray()) {
- // Requires JDK 7 or higher, Foo<int[]> is no longer GenericArrayType
+ }
+
+ // Requires JDK 7 or higher, Foo<int[]> is no longer GenericArrayType
+ if (((Class) genericClass).isArray()) {
return ((Class) genericClass).getComponentType();
- } else {
- return (Class<?>) genericClass;
}
+ return (Class<?>) genericClass;
} catch (Throwable e) {
- throw new IllegalArgumentException(cls.getName()
- + " generic type undefined!", e);
+ throw new IllegalArgumentException(cls.getName() + " generic type undefined!", e);
}
}
@@ -499,8 +504,8 @@ public final class ReflectUtils {
public static String getDesc(final CtMethod m) throws NotFoundException {
StringBuilder ret = new StringBuilder(m.getName()).append('(');
CtClass[] parameterTypes = m.getParameterTypes();
- for (int i = 0; i < parameterTypes.length; i++) {
- ret.append(getDesc(parameterTypes[i]));
+ for (CtClass parameterType : parameterTypes) {
+ ret.append(getDesc(parameterType));
}
ret.append(')').append(getDesc(m.getReturnType()));
return ret.toString();
@@ -710,27 +715,36 @@ public final class ReflectUtils {
} else if ("short".equals(name)) {
sb.append(JVM_SHORT);
} else {
- sb.append('L').append(name).append(';'); // "java.lang.Object" ==> "Ljava.lang.Object;"
+ // "java.lang.Object" ==> "Ljava.lang.Object;"
+ sb.append('L').append(name).append(';');
}
name = sb.toString();
} else {
if ("void".equals(name)) {
return void.class;
- } else if ("boolean".equals(name)) {
+ }
+ if ("boolean".equals(name)) {
return boolean.class;
- } else if ("byte".equals(name)) {
+ }
+ if ("byte".equals(name)) {
return byte.class;
- } else if ("char".equals(name)) {
+ }
+ if ("char".equals(name)) {
return char.class;
- } else if ("double".equals(name)) {
+ }
+ if ("double".equals(name)) {
return double.class;
- } else if ("float".equals(name)) {
+ }
+ if ("float".equals(name)) {
return float.class;
- } else if ("int".equals(name)) {
+ }
+ if ("int".equals(name)) {
return int.class;
- } else if ("long".equals(name)) {
+ }
+ if ("long".equals(name)) {
return long.class;
- } else if ("short".equals(name)) {
+ }
+ if ("short".equals(name)) {
return short.class;
}
}
@@ -790,10 +804,12 @@ public final class ReflectUtils {
case JVM_SHORT:
return short.class;
case 'L':
- desc = desc.substring(1, desc.length() - 1).replace('/', '.'); // "Ljava/lang/Object;" ==> "java.lang.Object"
+ // "Ljava/lang/Object;" ==> "java.lang.Object"
+ desc = desc.substring(1, desc.length() - 1).replace('/', '.');
break;
case '[':
- desc = desc.replace('/', '.'); // "[[Ljava/lang/Object;" ==> "[[Ljava.lang.Object;"
+ // "[[Ljava/lang/Object;" ==> "[[Ljava.lang.Object;"
+ desc = desc.replace('/', '.');
break;
default:
throw new ClassNotFoundException("Class not found: " + desc);
@@ -943,7 +959,7 @@ public final class ReflectUtils {
}
public static Object getEmptyObject(Class<?> returnType) {
- return getEmptyObject(returnType, new HashMap<Class<?>, Object>(), 0);
+ return getEmptyObject(returnType, new HashMap<>(), 0);
}
private static Object getEmptyObject(Class<?> returnType, Map<Class<?>, Object> emptyInstances, int level) {
@@ -952,64 +968,78 @@ public final class ReflectUtils {
}
if (returnType == null) {
return null;
- } else if (returnType == boolean.class || returnType == Boolean.class) {
+ }
+ if (returnType == boolean.class || returnType == Boolean.class) {
return false;
- } else if (returnType == char.class || returnType == Character.class) {
+ }
+ if (returnType == char.class || returnType == Character.class) {
return '\0';
- } else if (returnType == byte.class || returnType == Byte.class) {
+ }
+ if (returnType == byte.class || returnType == Byte.class) {
return (byte) 0;
- } else if (returnType == short.class || returnType == Short.class) {
+ }
+ if (returnType == short.class || returnType == Short.class) {
return (short) 0;
- } else if (returnType == int.class || returnType == Integer.class) {
+ }
+ if (returnType == int.class || returnType == Integer.class) {
return 0;
- } else if (returnType == long.class || returnType == Long.class) {
+ }
+ if (returnType == long.class || returnType == Long.class) {
return 0L;
- } else if (returnType == float.class || returnType == Float.class) {
+ }
+ if (returnType == float.class || returnType == Float.class) {
return 0F;
- } else if (returnType == double.class || returnType == Double.class) {
+ }
+ if (returnType == double.class || returnType == Double.class) {
return 0D;
- } else if (returnType.isArray()) {
+ }
+ if (returnType.isArray()) {
return Array.newInstance(returnType.getComponentType(), 0);
- } else if (returnType.isAssignableFrom(ArrayList.class)) {
- return new ArrayList<Object>(0);
- } else if (returnType.isAssignableFrom(HashSet.class)) {
- return new HashSet<Object>(0);
- } else if (returnType.isAssignableFrom(HashMap.class)) {
- return new HashMap<Object, Object>(0);
- } else if (String.class.equals(returnType)) {
+ }
+ if (returnType.isAssignableFrom(ArrayList.class)) {
+ return new ArrayList<>(0);
+ }
+ if (returnType.isAssignableFrom(HashSet.class)) {
+ return new HashSet<>(0);
+ }
+ if (returnType.isAssignableFrom(HashMap.class)) {
+ return new HashMap<>(0);
+ }
+ if (String.class.equals(returnType)) {
return "";
- } else if (!returnType.isInterface()) {
- try {
- Object value = emptyInstances.get(returnType);
- if (value == null) {
- value = returnType.newInstance();
- emptyInstances.put(returnType, value);
- }
- Class<?> cls = value.getClass();
- while (cls != null && cls != Object.class) {
- Field[] fields = cls.getDeclaredFields();
- for (Field field : fields) {
- if (field.isSynthetic()) {
- continue;
- }
- Object property = getEmptyObject(field.getType(), emptyInstances, level + 1);
- if (property != null) {
- try {
- if (!field.isAccessible()) {
- field.setAccessible(true);
- }
- field.set(value, property);
- } catch (Throwable e) {
+ }
+ if (returnType.isInterface()) {
+ return null;
+ }
+
+ try {
+ Object value = emptyInstances.get(returnType);
+ if (value == null) {
+ value = returnType.newInstance();
+ emptyInstances.put(returnType, value);
+ }
+ Class<?> cls = value.getClass();
+ while (cls != null && cls != Object.class) {
+ Field[] fields = cls.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.isSynthetic()) {
+ continue;
+ }
+ Object property = getEmptyObject(field.getType(), emptyInstances, level + 1);
+ if (property != null) {
+ try {
+ if (!field.isAccessible()) {
+ field.setAccessible(true);
}
+ field.set(value, property);
+ } catch (Throwable ignored) {
}
}
- cls = cls.getSuperclass();
}
- return value;
- } catch (Throwable e) {
- return null;
+ cls = cls.getSuperclass();
}
- } else {
+ return value;
+ } catch (Throwable e) {
return null;
}
}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ReflectUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ReflectUtilsTest.java
index cc090ca..8928fec 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ReflectUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ReflectUtilsTest.java
@@ -41,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@@ -73,6 +74,7 @@ public class ReflectUtilsTest {
assertThat(ReflectUtils.getBoxedClass(char.class), sameInstance(Character.class));
assertThat(ReflectUtils.getBoxedClass(byte.class), sameInstance(Byte.class));
assertThat(ReflectUtils.getBoxedClass(short.class), sameInstance(Short.class));
+ assertThat(ReflectUtils.getBoxedClass(String.class), sameInstance(String.class));
}
@Test
@@ -378,13 +380,13 @@ public class ReflectUtilsTest {
assertTrue(ReflectUtils.getEmptyObject(Map.class) instanceof Map);
assertTrue(ReflectUtils.getEmptyObject(Object[].class) instanceof Object[]);
assertEquals(ReflectUtils.getEmptyObject(String.class), "");
- assertEquals(ReflectUtils.getEmptyObject(short.class), Short.valueOf((short) 0));
- assertEquals(ReflectUtils.getEmptyObject(byte.class), Byte.valueOf((byte) 0));
- assertEquals(ReflectUtils.getEmptyObject(int.class), Integer.valueOf(0));
- assertEquals(ReflectUtils.getEmptyObject(long.class), Long.valueOf(0));
- assertEquals(ReflectUtils.getEmptyObject(float.class), Float.valueOf(0));
- assertEquals(ReflectUtils.getEmptyObject(double.class), Double.valueOf(0));
- assertEquals(ReflectUtils.getEmptyObject(char.class), Character.valueOf('\0'));
+ assertEquals(ReflectUtils.getEmptyObject(short.class), (short) 0);
+ assertEquals(ReflectUtils.getEmptyObject(byte.class), (byte) 0);
+ assertEquals(ReflectUtils.getEmptyObject(int.class), 0);
+ assertEquals(ReflectUtils.getEmptyObject(long.class), 0L);
+ assertEquals(ReflectUtils.getEmptyObject(float.class), (float) 0);
+ assertEquals(ReflectUtils.getEmptyObject(double.class), (double) 0);
+ assertEquals(ReflectUtils.getEmptyObject(char.class), '\0');
assertEquals(ReflectUtils.getEmptyObject(boolean.class), Boolean.FALSE);
EmptyClass object = (EmptyClass) ReflectUtils.getEmptyObject(EmptyClass.class);
assertNotNull(object);