Search code examples
javaandroidvisibilitykotlinmaterialdrawer

Parameter effective visibility conflict between java and kotlin


I'm trying to override bindView function:

import com.mikepenz.materialdrawer.model.PrimaryDrawerItem

open class SpinnerDrawerItem() : PrimaryDrawerItem(), View.OnClickListener {
  override fun bindView(viewHolder: ViewHolder?) {
    super.bindView(viewHolder)
    // Do things
  }
}

From PrimaryDrawerItem but I get:

enter image description here

Why?


Solution

  • PrimaryDrawerItem.ViewHolder is protected. And the bindView() method, which is public, accepts PrimaryDrawerItem.ViewHolder. But a general external caller cannot invoke this method because it cannot refer a protected nested class PrimaryDrawerItem.ViewHolder. Kotlin prohibits such behavior and requires either to make the parameter visibility equal to the method visibility or to decrease the parameter visibility to be less or equal to the method visibility.

    In your case you have to make PrimaryDrawerItem.ViewHolder public or make PrimaryDrawerItem.bindView() protected.