@Test public void canInstatnce() { assertFalse(ClassUtil.canInstatnce(null)); assertFalse(ClassUtil.canInstatnce(void.class)); assertTrue(ClassUtil.canInstatnce(double.class)); assertTrue(ClassUtil.canInstatnce(int[].class)); assertTrue(ClassUtil.canInstatnce(Void[].class)); assertTrue(ClassUtil.canInstatnce(Test[][].class)); assertTrue(ClassUtil.canInstatnce(String[].class)); assertFalse(ClassUtil.canInstatnce(Void.class)); assertTrue(ClassUtil.canInstatnce(Short.class)); assertFalse(ClassUtil.canInstatnce(Test.class)); assertFalse(ClassUtil.canInstatnce(Collections.class)); assertFalse(ClassUtil.canInstatnce(Serializable.class)); assertFalse(ClassUtil.canInstatnce(TimeUnit.class)); assertTrue(ClassUtil.canInstatnce(InnerStatic.class)); assertTrue(ClassUtil.canInstatnce(InnerStatic[].class)); assertTrue(ClassUtil.canInstatnce(String.class)); assertFalse(ClassUtil.canInstatnce(Inner.class)); assertFalse(ClassUtil.canInstatnce(Inner[].class)); }
public static <T> boolean canInstatnce(Class<T> clazz) { if (clazz == null) { return false; } if (clazz.isPrimitive()) { return clazz != void.class; } if (clazz.isArray() && Modifier.isPublic(getArrayComponentType(clazz).getModifiers())) { return true; } int modifier = clazz.getModifiers(); if (Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)) { return false; } Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (Modifier.isPublic(constructor.getModifiers())) { return true; } } return false; }
ClassUtil { public static <T> boolean canInstatnce(Class<T> clazz) { if (clazz == null) { return false; } if (clazz.isPrimitive()) { return clazz != void.class; } if (clazz.isArray() && Modifier.isPublic(getArrayComponentType(clazz).getModifiers())) { return true; } int modifier = clazz.getModifiers(); if (Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)) { return false; } Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (Modifier.isPublic(constructor.getModifiers())) { return true; } } return false; } }
ClassUtil { public static <T> boolean canInstatnce(Class<T> clazz) { if (clazz == null) { return false; } if (clazz.isPrimitive()) { return clazz != void.class; } if (clazz.isArray() && Modifier.isPublic(getArrayComponentType(clazz).getModifiers())) { return true; } int modifier = clazz.getModifiers(); if (Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)) { return false; } Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (Modifier.isPublic(constructor.getModifiers())) { return true; } } return false; }  }
ClassUtil { public static <T> boolean canInstatnce(Class<T> clazz) { if (clazz == null) { return false; } if (clazz.isPrimitive()) { return clazz != void.class; } if (clazz.isArray() && Modifier.isPublic(getArrayComponentType(clazz).getModifiers())) { return true; } int modifier = clazz.getModifiers(); if (Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)) { return false; } Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (Modifier.isPublic(constructor.getModifiers())) { return true; } } return false; }  static String getClassNameAsResource(String className); static Class<?> getPrimitiveType(String name); static Class<?> getPrimitiveType(Class<?> type); @SuppressWarnings("unchecked") static Class<T> getWrapperTypeIfPrimitive(Class<T> type); static T getPrimitiveDefaultValue(Class<T> type); static boolean isPrimitiveOrWrapper(Class<?> clazz); static Class<?> getArrayClass(Class<?> componentType); static Class<?> getArrayClass(Class<?> componentClass, int dimension); static Class<?> getArrayComponentType(Class<?> type); static boolean isInstance(Class<?> clazz, Object object); static boolean canInstatnce(Class<T> clazz); static List<Class<?>> getAllSuperclasses(Class<?> clazz); static Class<?>[] getAllSuperclassesAsArray(Class<?> clazz); static List<Class<?>> getAllInterfaces(Class<?> clazz); static Class<?>[] getAllInterfacesAsArray(Class<?> clazz); static Set<Class<?>> getAllInterfacesAsSet(Class<?> clazz, ClassLoader classLoader); static boolean isVisible(Class<?> clazz, ClassLoader classLoader); static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader); static boolean isInterfaceImpl(Class<?> thisClass, Class<?> targetInterface); static boolean isSubClass(Class<?> thisClass, Class<?> target); static boolean isAssignable(Class<?>[] classes, Class<?>[] fromClasses); static boolean isAssignable(Class<?> clazz, Class<?> fromClass); static String locateClass(Class<?> clazz); static String locateClass(String className); static String locateClass(String className, ClassLoader loader); static String getFriendlyClassNameForObject(Object object); static String getFriendlyClassName(Class<?> clazz); static String getFriendlyClassName(String javaClassName); static String getSimpleClassNameForObject(Object object); static String getSimpleClassNameForObject(Object object, boolean processInnerClass); static String getSimpleClassName(Class<?> clazz); static String getSimpleClassName(Class<?> clazz, boolean proccessInnerClass); static String getSimpleClassName(String javaClassName); static String getSimpleClassName(String javaClassName, boolean proccesInnerClass); static String getSimpleMethodSignature(Method method); static String getSimpleMethodSignature(Method method, boolean withClassName); static String getSimpleMethodSignature(Method method, boolean withModifiers, boolean withReturnType,
            boolean withClassName, boolean withExceptionType); static String getShortClassName(String className); static String getShortClassName(Class<?> clazz); }
ClassUtil { public static <T> boolean canInstatnce(Class<T> clazz) { if (clazz == null) { return false; } if (clazz.isPrimitive()) { return clazz != void.class; } if (clazz.isArray() && Modifier.isPublic(getArrayComponentType(clazz).getModifiers())) { return true; } int modifier = clazz.getModifiers(); if (Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)) { return false; } Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (Modifier.isPublic(constructor.getModifiers())) { return true; } } return false; }  static String getClassNameAsResource(String className); static Class<?> getPrimitiveType(String name); static Class<?> getPrimitiveType(Class<?> type); @SuppressWarnings("unchecked") static Class<T> getWrapperTypeIfPrimitive(Class<T> type); static T getPrimitiveDefaultValue(Class<T> type); static boolean isPrimitiveOrWrapper(Class<?> clazz); static Class<?> getArrayClass(Class<?> componentType); static Class<?> getArrayClass(Class<?> componentClass, int dimension); static Class<?> getArrayComponentType(Class<?> type); static boolean isInstance(Class<?> clazz, Object object); static boolean canInstatnce(Class<T> clazz); static List<Class<?>> getAllSuperclasses(Class<?> clazz); static Class<?>[] getAllSuperclassesAsArray(Class<?> clazz); static List<Class<?>> getAllInterfaces(Class<?> clazz); static Class<?>[] getAllInterfacesAsArray(Class<?> clazz); static Set<Class<?>> getAllInterfacesAsSet(Class<?> clazz, ClassLoader classLoader); static boolean isVisible(Class<?> clazz, ClassLoader classLoader); static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader); static boolean isInterfaceImpl(Class<?> thisClass, Class<?> targetInterface); static boolean isSubClass(Class<?> thisClass, Class<?> target); static boolean isAssignable(Class<?>[] classes, Class<?>[] fromClasses); static boolean isAssignable(Class<?> clazz, Class<?> fromClass); static String locateClass(Class<?> clazz); static String locateClass(String className); static String locateClass(String className, ClassLoader loader); static String getFriendlyClassNameForObject(Object object); static String getFriendlyClassName(Class<?> clazz); static String getFriendlyClassName(String javaClassName); static String getSimpleClassNameForObject(Object object); static String getSimpleClassNameForObject(Object object, boolean processInnerClass); static String getSimpleClassName(Class<?> clazz); static String getSimpleClassName(Class<?> clazz, boolean proccessInnerClass); static String getSimpleClassName(String javaClassName); static String getSimpleClassName(String javaClassName, boolean proccesInnerClass); static String getSimpleMethodSignature(Method method); static String getSimpleMethodSignature(Method method, boolean withClassName); static String getSimpleMethodSignature(Method method, boolean withModifiers, boolean withReturnType,
            boolean withClassName, boolean withExceptionType); static String getShortClassName(String className); static String getShortClassName(Class<?> clazz); static final char INNER_CLASS_SEPARATOR_CHAR; static final String INNER_CLASS_SEPARATOR; }