This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Nested Interface  RSS feed

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a doubt regarding inner classes and interfaces. Can anyone please clarify this to me. Consider the below code and tell me why it gives error in the lines commented,



Thanks in advance.

Regards,
Jothi Shankar Kumar. S
 
Rajesh Kadle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In both cases static reference is made to non-static fileds, hence the compiler error.

Static context relates to class, it works with class. It has no reference like this or super, so we cant access the non-static fields from static context.

Other way, accessing static fields from non-static context is allowed as each instance is related to the class.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,

I just want to know if in the above code, the line,

interface StaticMemberInterface_1{int kk = 2000;}

Is kk implicitly static?

Regards,
Jothi Shankar Kumar. S
 
Rajesh Kadle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, all fields inside an interface are implicitly static and final.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!