-1

For example ,

public void test (int p1, final List p2,final String p3) {

}

I noticed that there is one more line ahead the method after it compiled to smali

# virtual methods

What does it mean? Does it mean that the parameter has a final modifier? If so, how does it express which parameter is final?

rockwe
  • 11
  • 4

1 Answers1

1

"final" on parameters is a purely java concept that is not really expressed in the bytecode. However, the dex specification does have an allowance for this, by way of the MethodParameters annotation. Although this is an optional piece of metadata, and I'm not sure if any compilers will actually add this annotation to the dex file.

The "virtual methods" thing is not related to the final parameters. The dex format define 2 categories of methods. Virtual methods and direct methods. Direct methods are methods that cannot be overridden by a subclass, while virtual methods can be. private methods, static methods and constructors are direct, while anything else is virtual.

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
  • ,I would say thank you. But static methods can be overridden in subclass,so it is virtual methods ,isn't it? – rockwe Mar 03 '20 at 00:38
  • No they can't. :) See, e.g. https://stackoverflow.com/questions/2223386/why-doesnt-java-allow-overriding-of-static-methods – JesusFreke Mar 03 '20 at 06:05
  • public class StaticClass2 extends StaticClass { public static String test(String p1){ return "StaticClass2 :" + p1; } public static void main(String[] args) { String result2 = StaticClass.test("111"); String result = StaticClass2.test("dddd"); System.out.println(result); System.out.println(result2); } } – rockwe Mar 25 '20 at 04:27
  • public class StaticClass { public static String test(String p1){ System.out.println("in StaticClass test"); return "StaticClass; " + p1; } } – rockwe Mar 25 '20 at 04:27
  • The test() method in each class is completely separate. They don't override each other. If you use StaticClass.test(), you get the method defined in StaticClass, and if you use StaticClass2.test(), you get the method defined in StaticClass2. – JesusFreke Mar 25 '20 at 08:08
  • For example, if try to add @Override to the StaticClass2.test() method, the compiler will complain, because it's not actually overriding anything. – JesusFreke Mar 25 '20 at 08:13