Shadowing methods / fields from extended class


#1

In Android there is class (java):

 public static abstract class ViewHolder {
 public final View itemView;
 public ViewHolder(View itemView) { this.itemView = itemView; }
 ....
}

When I extend it I can’t declare my own variable as “itemView”, because it says there is already itemView (from extended class). Same goes for methods (for example: fun isRecyclable() : Boolean{return true})

Do I do something wrong or shadowing while extending doesn’t work? For now I use other viariable names, but this doesn’t seem like good way at all. When I call “super.itemView” compilator knows which field I want to get. But it doesn’t understand “this.itemView” as it shows that both values are declared and doesn’t know which one to pick.

Ofc I can use changed names, but in the long run it will be exhausting, especially when using deep inherits!

I tried doing some tricks and searched a lot to learn how to make my life easier with this problem, but I can’t find proper answer for now. Hope I will find help or at least straight answer.

Greetings,
Janusz

Edit:

open class Test( open val itemView: View)

class MyViewHolder(override var itemView: View) : Test(itemView)

When it is defined like this it works just like shadowing (this.itemView = itemView and super.itemView is Test’s itemView). So in kotlin we will just have to add “open” keywords, exhausting for sure, but not hacking. Well… It seems it is still worse than shadowing as I can’t weaken visibility of “shadowed” field.

Still problem with java code referenced by kotlin is not working properly when it comes to shadowing as final modifier in java allows to shadow whereas kotlin doesn’t.