• Post Reply Bookmark Topic Watch Topic
  • New Topic

variables in interface  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Why are variables in interface contants ? Please advice.

Thanks
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deeps sinha wrote:Why are variables in interface contants ?

Because it doesn't make sense to define a variable in an interface. For a start, it would have to be static, and that's usually a big no-no.

Winston
 
deeps sinha
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for helping me Winston,
I understand that for a start it must be declared static, because there are no constructors concept with interfaces.
but why final ?
Also I could not understand what is big no no. If you could elaborate a bit it would be nice.
 
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because that variable would have to be shared with all instances. It was originally thought that variables in interfaces were useful, but now it has been realised that, often, all you achieve is enlarging the public interface of implementing classes. You usually want to keep a class’ public interface small.
 
deeps sinha
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks....
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!