Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Pull up method refactoring": Code behavior changes due to reflection #1871

Open
assdfsdafasfa opened this issue Dec 19, 2024 · 0 comments
Open

Comments

@assdfsdafasfa
Copy link

Select doSomething() and click Pull up refactoring, resulting in Class.forName("A") not being able to get the method name based on the class.
Code before refactoring:

import java.lang.reflect.Method;
class A extends B{
    public void doSomething() {
        System.out.println("In A");
    }
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("A");
        Method method = clazz.getMethod("doSomething");
        method.invoke(clazz.newInstance());
    }
}
class B {
}

Code after refactoring:

import java.lang.reflect.Method;
class A extends B{
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("A");
        Method method = clazz.getMethod("doSomething");
        method.invoke(clazz.newInstance());
    }
}
class B {
    public void doSomething() {
        System.out.println("In A");
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant