This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Interface implementation problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my application, my concrete class(MyClass) needs to implement a interface(ParentInterface).
There is only one method in MyInteface(MyMethod())

Also it is required to extend class(ParentClass) having only
one static method with same name(static MyMethod()).
Method in ParentClass is static.
I need to override the method in MyClass.

When i am trying to do this, compiler complains that MyMethod present in MyInterface is not defined which is non-static method.
Since i have already defined static MyMethod, another method with same name is restricted.
I can't manipulate ParentClass or ParentInterface.

Is there any way to get out of this situation??

[ October 23, 2007: Message edited by: Saurabh Gupta ]

[ October 23, 2007: Message edited by: Saurabh Gupta ]
[ October 23, 2007: Message edited by: Saurabh Gupta ]
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no way out without relaxing one of your criteria -- i.e., either the class doesn't directly extend the parent, or doesn't directly implement the interface.

One thing you could do is extend the parent, but don't implement the interface; then provide a method named something like "asParentInterface()" that returns an instance of another class (perhaps an inner class) which implements the interface and the method, using the data in your main class as needed.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem really has nothing to do with ParentClass, it's the fact that you must implement the method defined in the interface, and declaring it static does not fulfill that requirement.

And, as you may see on this forum - it's not possible to override static methods. Overriding implies dynamic dispatch, and static do not have dynamic dispatch - they have no context in which to dynamically choose the implementation.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic