阅读背景:

Java:泛型:使对象从泛型方法中键入T并访问其方法

来源:互联网 
    public interface MyMapperInterface<Y, Z> {

    Y map(Z zObject);

    }

    public class One{
    }

    public class Two{
    }


    public MapperOneTwo  implements MyMapperInterface<One, Two> {

        public One map(Two twoObject){
            //Based on properties of Two, a new One Object is created and returned.
        }

    }


public MapperThreeFour  implements MyMapperInterface<Three, Four> {

        public One map(Two twoObject){
            //Now for two other class, Three and Four, there is a new 
              mapper.
              Based on properties of Two, a new One Object is created and 
               returned.
        }

    }





    FactoryClass

    public class Factory {

        public <T> T getClassInstance(String params){
          if (params.equals("a")) { 
    return (T) new MapperOneTwo();
    } else if (params.equals("b")){
    return (T) new MapperThreeFour();
    }
    }

    }
    public interface MyMapperInterface<Y, Z> {



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: