• Post Reply Bookmark Topic Watch Topic
  • New Topic

Variables in interface  RSS feed

 
Rajasekar Elango
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I know the variables in interface are public static final by default and a top level interface should also be public.

Now my question is to use interface only declare/use constants (not any methods) we can use it from anywhere by using interfacename.variable, but will there be any situation where we want to implement that interface just to use final variables..?

Thanks,
Raja
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to "implement" an interface, just to get the constants defined therein. However, it is generally agreed to be bad practice.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Java 5, static imports allow you to selectively import just the constants you need from an interface or class. Java purists consider imports ending in .* to be a crude instrument. Implementing an inteface just to acquire its constants would be similarly deprecated.
 
Rajasekar Elango
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies..

- Raja
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!