Android method with default (package) visibility overriding (shouldn't work, but does - why?)

后端 未结 1 1672
情话喂你
情话喂你 2020-12-05 16:23

I\'ve been playing around with SVG support in Android and came up with this library which claims that it supports SVG just as it they were native.

Since I took great

相关标签:
1条回答
  • 2020-12-05 17:13

    It looks like there is a bug in the Dalvik interpreter which allows package-private methods to be overridden. Apparently, Google recognized this issue (in Jelly Bean?), as Dalvik reports a warning that it is incorrectly overriding a package-private method in this case, and ART reports it as an error and fails to compile it. The correct behaviour would of course be to allow it but not allow overriding package-private methods from other packages, but it looks like Google want to avoid breaking existing applications that depend on this behaviour.

    UPDATE: This is now officially confirmed in the ART documentation update on June 16, although it states that ART issues a warning instead of a critical error as velis reported in the comments on the question:

    Dalvik incorrectly allowed subclasses to override package-private methods. ART issues a warning in such cases:

    Before Android 4.1, method void com.foo.Bar.quux()
    would have incorrectly overridden the package-private method in
    com.quux.Quux

    If you intend to override a class's method in a different package, declare the method as public or protected.

    0 讨论(0)
提交回复
热议问题