Skip to content Skip to sidebar Skip to footer

Android Method With Default (package) Visibility Overriding (shouldn't Work, But Does - Why?)

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 pains in discov

Solution 1:

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.

Post a Comment for "Android Method With Default (package) Visibility Overriding (shouldn't Work, But Does - Why?)"