Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why static binding for Member variables alone?  RSS feed

 
Vinodh Ramadoss
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was just wondering why is that only member variable have static binding i.e they are decided by the object reference type while methods have the privelege of being decided at run time(object pointed to matters). So simplay why is that instance methods support polymorphism while member variables do not?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting question. As to why, I guess it's just the language designer's choice. It kinda makes sense - you can override a method to change behavior, requiring late binding. But there's not much point in overriding a variable since it has no behavior. So maybe they figured if you defined a variable again, you must really want a distinct variable. Which assumes you did it on purpose, and I've done it by mistake many more times than on purpose!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!