Calling protected static methods


#1

Is there a way to call a protected static method from a derived class in kotlin?

Example:
I am extending android.widget.LinearLayout and I’d like to call protected static int[] mergeDrawableStates from android.view.View (LinearLayout extends View, but not directly).


#2

Yes, this is known problem. Fill free to vote this issue http://youtrack.jetbrains.com/issue/KT-2999 (also there is a temporary workaround)


#3

The workaround is to create an intermediary class in java with either:   - a non-static method forwarding the call to the protected static method   - a public static method forwarding the call to the protected static method. I have used that workaround in the past, but was looking for something better.

For this particular case, I ended up duplicating the functionality of the static method (it’s static and didn’t need to be inside View, and it’s only a few lines long).

Another obvious workaround is to use reflection to call it.