class a<F,G>
{
void make(F x,G y){
x.put1();
y.put1();
}
}
class b
{
public void put1(){
System.out.println("我是B类");
}
}class c
{
public void put1(){
System.out.println("我是C类");
}
}class ex519
{
public static void main(String args[])
{
a<b,c> mm=new a<b,c>();
b xx=new b();
c yy=new c();
mm.make(xx,yy);
}
}

解决方案 »

  1.   

    class a<F,G>
    a<b,c> mm=new a<b,c>();  //这两个定义的类型相同吗?
      

  2.   

    F和G是什么东东,应该b和c类的接口吧? 那么b类应该实现F,c类应该实现G
      

  3.   

    你不理解泛型程序设计,泛型不是这么运用的,泛型是运用一个通用的引用去指向对象,不过在指向对向之前可以动态的指定对象的类型。
    class a<F,G>
    {
    void make(F x,G y){
    x.put1();
    y.put1();
    }
    }
    这个里面指定的f,g泛型,类是不可能知道它指向什么东西,当然也不可能知道f,g里面会有putl();这个方法,这里在这里运用显然是错误的。
      

  4.   

    你写的这些功能并不好体现泛型的设计的优势,反而让泛型变成了设计的绊脚石。
    class a<F,G>
    {
    void make(F x,G y){
    x.put1();
    y.put1();
    }
    }
    该成
    class a<F,G>
    {
    void make(F x,G y){
    ((b)x).put1();
    ((c)y).put1();
    }
    }但是你觉得这样的话,用泛型就无任何意义,直接传b,c要好得多。
    至于泛型的意义,你可以参考集合类的实现代码。
      

  5.   

    interface SomeInterface
    {
    public void put1();
    }class A<F extends SomeInterface, G extends SomeInterface>
    {
    void make(F x,G y)
    {
    x.put1();
    y.put1();
    }
    }class B implements SomeInterface
    {
    public void put1()
    {
    System.out.println("我是B类");
    }
    }class C implements SomeInterface
    {
    public void put1()
    {
    System.out.println("我是B类");
    }
    }public class ex519
    {public static void main(String[] args)
    {
    A<B, C> mm=new A<B, C>();
    B xx=new B();
    C yy=new C();
    mm.make(xx,yy);
    }}
    把公共部分接口化。
      

  6.   

    经过我的改动  可以正确运行:interface Put1 {
    void put1();
    }class A<F extends Put1, G extends Put1> {
    void make(F x, G y) {
    x.put1();
    y.put1();
    }
    }class B implements Put1{
    public void put1() {
    System.out.println("我是B类");
    }
    }class C implements Put1{
    public void put1() {
    System.out.println("我是C类");
    }
    }public class ex519 {
    public static void main(String args[]) {
    A<B, C> mm = new A<B, C>();
    B xx = new B();
    C yy = new C();
    mm.make(xx, yy);
    }
    }