[ 
https://issues.apache.org/jira/browse/LANG-1649?focusedWorklogId=567874&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-567874
 ]

ASF GitHub Bot logged work on LANG-1649:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Mar/21 18:10
            Start Date: 17/Mar/21 18:10
    Worklog Time Spent: 10m 
      Work Description: arturobernalg commented on a change in pull request 
#731:
URL: https://github.com/apache/commons-lang/pull/731#discussion_r596268511



##########
File path: src/main/java/org/apache/commons/lang3/ClassUtils.java
##########
@@ -935,6 +935,60 @@ public static boolean isAssignable(Class<?> cls, final 
Class<?> toClass, final b
         return toClass.isAssignableFrom(cls);
     }
 
+    /**
+     * Check if the given {@code Method} is overridable in the given target 
{@code Class}.
+     *
+     * <p>This method returns {@code false} for any {@code null} input or 
method with the static or final modifiers.</p>
+     * <pre>
+     * <code>
+     *   private static class ABG {
+     *        private void privateMethod() {
+     *        }
+     *        void defaultMethod() {
+     *        }
+     *        public void publicMethod() {
+     *        }
+     *        public final void finalMethod() {
+     *        }
+     *        public static void  staticMethod() {
+     *        }
+     *    }
+     *   Method publicMethod  = ABG.class.getDeclaredMethod("publicMethod", 
null)
+     *   Method privateMethod = ABG.class.getDeclaredMethod("privateMethod", 
null)
+     *   Method defaultMethod = ABG.class.getDeclaredMethod("defaultMethod", 
null)
+     * </code>
+     *
+     * ClassUtils.isOverridable(null, null)                = false
+     * ClassUtils.isOverridable(null, Class)               = false
+     * ClassUtils.isOverridable(Class, null)               = false
+     * ClassUtils.isOverridable(privateMethod, ABG.class)) = false
+     * ClassUtils.isOverridable(defaultMethod, ABG.class)) = true
+     * ClassUtils.isOverridable(publicMethod, ABG.class))  = true
+     * ClassUtils.isOverridable(finalMethod, ABG.class))   = false
+     * ClassUtils.isOverridable(staticMethod, ABG.class))  = false
+     * </pre>
+     *
+     * @param method the method to check, may be {@code null}
+     * @param cls the target class to check against, may be {@code null}
+     * @return {@code true} if the is overridable, false if not or any {@code 
null} input
+     * @since 3.13.0
+     */
+    public static boolean isOverridable(final Method method, final Class<?> 
cls) {
+        if (ObjectUtils.anyNull(method, cls)) {
+            return false;
+        }
+        if (Modifier.isStatic(method.getModifiers())) {

Review comment:
       & cannot be applied to int. Will not work. And IMO to more complex and 
hard to read




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 567874)
    Time Spent: 2h 50m  (was: 2h 40m)

> Check if method is Overridable
> ------------------------------
>
>                 Key: LANG-1649
>                 URL: https://issues.apache.org/jira/browse/LANG-1649
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.12.0
>            Reporter: Arturo Bernal
>            Priority: Minor
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> Create a method that Check if the given  Method is overridable in the given a 
>  Class
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to