本帖最后由 dyguest 于 2012-04-08 22:17:25 编辑

解决方案 »

  1.   

    你的 Card 跟 Poker 应该存在继承关系的吧?
      

  2.   

    嗯.对的,我忘了说了
    Element
     |-Card
       |-Poker
    的这样.不过还是不明白为什么p.putElement()的参数是 Card型的,而不是Poker型的??
    应该怎么改呢..??
      

  3.   

    没太理解你的问题是啥,改成:
    p.putElement(new Poker("Card 2"));
    不行么?
      

  4.   

    改为p.putElement(new Poker(""));没什么问题吧。应该只要是Element的子类都可以的啊
      

  5.   


    没是没问题,但是我的目的是让p.putElement()的参数类型是 Poker 而不是 Card 啊!
      

  6.   

    已经弄明白了,感谢各位了.正确的改法是:public class Collection<E extends Element> extends Element {
        public void putElement(E el){...}
    }public class CardCollection<C extends Card> extends Collection<C> {}public class PokerCollection<P extends Poker> extends CardCollection<P> {}
    这样的话泛型的继承就对了,以上,ありがとう