Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Overriding methods declaration problems

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Overriding methods declaration problems

    Hello! I have recently joined this forum, so I donīt know if I am doing it correctly posting this thread here.

    I am having problems with this:

    I want develop an interface IB that extends an interface IA

    Interface IA has a method :

    void M(IC pIC );

    and interface IB, has a method :

    void M(ID pID);

    Also happends that interface ID extends interface IC, so I want that interface's IB method M declaration overrides interface's IA method M declaration. Then when an Object implements interface IB, it will have to implement method "void M(ID pID);" but not the method "void M(IC pIC );".

    My questions are:

    This can be done?

    If it can be done, how can I make it?

    Thanks for helpping me, or for trying to help.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,684
    Thanks
    25
    Thanked 333 Times in 309 Posts

    Default Re: Overriding methods declaration problems

    I'll attempt to help you out more in about an hour or so when I can get back on a computer. For the time being, I have one question to make sense of this for me. What is the purpose and/or benefit for several interfaces implementing each other in your context?

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    TurboTuring (July 9th, 2010)

  4. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Overriding methods declaration problems

    In fact, IA and IB are interfaces of view controllers, and IC and ID ar interfaces of views.

    IA is implemented by an abstract class that represents a general kind of view controller, and IB is implemented by a class that represents a concrete view controller.

    IC is implemented by an abstract class that represents a general kind of view, and IB is implemented by a class that represents a concrete view.

    The method M in fact is a method that sets one attribute of the view controller which implements it. It sets the "view" attribute for that controller, and depending on the controller class, that attribute may be a class of kind IC or of kind ID. That way, allowing to the implementers of IB (concrete controllers) execute void M(IC pIC); may be wrong, because IC its implemented by a (general view).

    I donīt know if I am explaining it correctly.

    Any more question you want to ask, just tell me.

    Thanks.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,010
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Overriding methods declaration problems

    This can be done?
    What happens when you write a simple program to test it?
    The compiler will tell you very quickly if it "can be done". No sense waiting for someone at a forum to try it.

  6. The Following User Says Thank You to Norm For This Useful Post:

    TurboTuring (July 9th, 2010)

  7. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Overriding methods declaration problems

    Sorry, I forgot to post what the compiler told me. If a program it, without using generics, it tells me that I have to implement both methods :
    void M(IC pIC);
    void M(ID pID);
    in the class that implements IB.

    I also tried :

    public interface IA {
       <IZ extends IC>void method(IZ pIZ);
    }
     
    public interface IB extends IA {
        <IZ extends IC,ID> void method(IZ pIZ);
     
    }

    An also tells me to implement both methods, but when I implement them, it says me that there is an error because both methods have the same erasure. So I tried to change the order of extends IC,ID to extends ID,IC, but it tells me to implement both. Finally I tried :
    public interface IA<IZ extends IC> {
       <IZ extends IC>void method(IZ pIZ);
    }
     
    public interface IB<IZ extends ID,IC> extends IA<IZ> {
        <IZ extends ID,IC> void method(IZ pIZ);
    }
    An again tells me the same. An if then I change extends ID,IC to extends IC,ID, having the same erasure, I get overriden the method but with void M(IC pIC ); and not with void M(ID pID);

    I am beggining to think that it canīt be done.

    Thanks.
    Last edited by helloworld922; July 9th, 2010 at 01:54 PM.

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,010
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Overriding methods declaration problems

    The compile would tell you if what you are doing is wrong.

  9. The Following User Says Thank You to Norm For This Useful Post:

    TurboTuring (July 9th, 2010)

  10. #7
    Junior Member
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Overriding methods declaration problems

    IB's void M doesn't really override IA's void M because IB's method restricts the arguments to only ID's so ID is different from IC. Therefore void M would be an overloaded method.

  11. The Following User Says Thank You to cosecant For This Useful Post:

    TurboTuring (July 9th, 2010)

Similar Threads

  1. Very beginner - What's wrong in my applet declaration?
    By rforte in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 30th, 2010, 04:54 AM
  2. methods help
    By hockey87 in forum AWT / Java Swing
    Replies: 1
    Last Post: March 9th, 2010, 10:57 PM
  3. Calling for methods
    By soccer_kid_6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 28th, 2010, 11:13 PM
  4. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 04:04 PM
  5. Working with Methods
    By duckman in forum Object Oriented Programming
    Replies: 3
    Last Post: November 9th, 2009, 07:27 PM

Tags for this Thread