java.lang.NoSuchMethodError error caused by static method

java.lang.NoSuchMethodError error caused by static method

When you modify bug Today, the variability out of the class file directly to the test test test results when tested throws an java.lang.NoSuchMethodErrorerror, this error indicates that, when running the program, call the object method does not exist. I can be a normal local environment compiler and running, why they did not do it the environment, investigation log, locate the error, the relevant two class files pulled out from a test environment, decompile, the issue is because the cause static method The problem.
For ease of description and to avoid leaks me here defines two classes A and B.
Class A

public class A {
    public void f2() {
        System.out.println("invoke f2");
        new B().f1();
    }
}

Class B

public class B {
    public static void f1() {
        System.out.println("invoke f1");
    }
}

A method called f2 f1 class method of the class B, this would have been no problem, but the problem has appeared in the static method above. Initially f1 methods of the class B is not static, so the A class method needs to call f1 B first instantiated, after this code is compiled into a test environment, then I change the A class, to pull new svn code, the method of the class B f1 by others instead of the static, I only modify part of the code a, and then compilation of the a compiled class files into the test environment to test, so they reported this mistake.

Exception in thread "main" java.lang.NoSuchMethodError: test.B.f1()V
    at test.A.f2(A.java:6)
    at test.App.main(App.java:5)

The most relevant methods began to think there is, there is no problem parameters, how is there such a problem then, until decompile the results realized.
A class decompile results

public class A { public void f2() { System.out.println("invoke f2");
    new B();B.f1();
  }
}

While calling f2 f2 in Method B Method B to A class is instantiated, but the call B, f1 or static method call used, and examples irrelevant, static methods and classes binding.

Guess you like

Origin www.cnblogs.com/ZiYangZhou/p/11588236.html