/** * @return An array of all locally declared methods or equivalent thereof * (such as default methods on Java 8 based interfaces that the given class * implements). */ public static Method[] getLocalMethods(Class<?> clazz) { Method[] result; Method[] declaredMethods = excludingMain(clazz); List<Method> defaultMethods = getDefaultMethods(clazz); if (defaultMethods != null) { result = new Method[declaredMethods.length + defaultMethods.size()]; System.arraycopy(declaredMethods, 0, result, 0, declaredMethods.length); int index = declaredMethods.length; for (Method defaultMethod : defaultMethods) { result[index] = defaultMethod; index++; } } else { List<Method> prunedMethods = Lists.newArrayList(); for (Method declaredMethod : declaredMethods) { if (!declaredMethod.isBridge()) { prunedMethods.add(declaredMethod); } } result = prunedMethods.toArray(new Method[prunedMethods.size()]); } return result; }
/** * @return An array of all locally declared methods or equivalent thereof (such as default methods * on Java 8 based interfaces that the given class implements). */ public static Method[] getLocalMethods(Class<?> clazz) { Method[] declaredMethods = excludingMain(clazz); List<Method> defaultMethods = getDefaultMethods(clazz); if (defaultMethods == null) { List<Method> prunedMethods = Lists.newArrayList(); for (Method declaredMethod : declaredMethods) { if (!declaredMethod.isBridge()) { prunedMethods.add(declaredMethod); } } return prunedMethods.toArray(new Method[0]); } Method[] result = new Method[declaredMethods.length + defaultMethods.size()]; System.arraycopy(declaredMethods, 0, result, 0, declaredMethods.length); int index = declaredMethods.length; for (Method defaultMethod : defaultMethods) { result[index] = defaultMethod; index++; } return result; }