Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Methods

 
Ray Dawson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to implement an interface with some methods, but all of these methods are static.
The problem now is all of the code which I have is for Client side & all are static i.e. about 300 variables & 50 functions calls are all done as static. But now if I want to change these back to non-static I have to create numerous objects.

Is there anyway I can use static methods in interface ???

BTW, I'm using RMI Remote Interface, how can I use static methods in RMI ???
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can't declare static methods in interfaces, and then have classes that implement the interface with implementations of those methods. Static methods are not polymorphic: the rules for non-static methods don't work; you can't override static methods.

If your application is defined with lots of static methods and variables, then it is not at all object oriented, but very much procedural. And because of that you can't use features such as interfaces, because those only work well in an OO design. You'll have to redesign the application in an object oriented way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic