Results 1 to 2 of 2
  1. #1
    Tim99 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Generics and Inheritance

    Hi,

    I'm stuck with a generics problem. Here it is in very simplified form:

    Java Code:
     public abstract class Animal {
    }
    
    public class Elephant extends Animal {
    }
    
    public class Crocodile extends Animal {
    }
    
    
    public abstract class Zookeeper {
      public abstract void feed(??? extends Animal??? a);
    }
    
    public abstract class ElephantKeeper extends Zookeeper {
      public void feed(Elephant e) {
      }
    }
    
    public abstract class CrocodileKeeper extends Zookeeper {
      public void feed(Crocodile c) {
      }
    }
    My question now is: How does the parameter for the Zookeeper's feed-method look like? Is this possible at all or do I mandatory have to use something like

    Java Code:
    public abstract class Zookeeper<X extends Animal>
    ...which I want to avoid. Any help is greatly appreciated!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Generics and Inheritance

    Quote Originally Posted by Tim99 View Post

    .....

    My question now is: How does the parameter for the Zookeeper's feed-method look like? Is this possible at all or do I mandatory have to use something like

    Java Code:
    public abstract class Zookeeper<X extends Animal>
    ...which I want to avoid. Any help is greatly appreciated!
    Why do you want to avoid this?

Similar Threads

  1. generics
    By arik23 in forum New To Java
    Replies: 2
    Last Post: 04-21-2011, 04:28 PM
  2. generics
    By arik23 in forum New To Java
    Replies: 3
    Last Post: 04-19-2011, 10:31 AM
  3. Need Help with Using Generics
    By badbeauty in forum Advanced Java
    Replies: 3
    Last Post: 04-09-2011, 08:07 AM
  4. generics and inheritance
    By tawalaya in forum Advanced Java
    Replies: 5
    Last Post: 04-08-2011, 08:32 PM
  5. Generics & Inheritance Question
    By Lee Rhodes in forum Advanced Java
    Replies: 3
    Last Post: 07-03-2009, 05:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •