本帖最后由 xiaolongren1989 于 2014-03-07 11:37:59 编辑

解决方案 »

  1.   

    Cannot make a static reference to the non-static type 这个意思应该很明确了,去掉max方法中的static
      

  2.   

    Cannot make a static reference to the non-static type 
    非静态引用不能使用静态引用
      

  3.   

    public static DataType  max(DataType a, DataType b) {
    改为
    public DataType  max(DataType a, DataType b) {
      

  4.   

    谢谢解答,我了解这个报错的改正方法;但是我想用使我写的这个泛型的max成为这种Math.max()这样来调用,怎么实现那?
      

  5.   

    谢谢解答,我了解这个报错的改正方法;但是我想用使我写的这个泛型的max成为这种Math.max()这样来调用,怎么实现那?
      

  6.   

    谢谢解答,我了解这个报错的改正方法;但是我想用使我写的这个泛型的max成为这种Math.max()这样来调用,怎么实现那? 
      

  7.   

    泛型放在方法上public class Max {
        public static <T  extends Comparable < T >> T  max(T a, T b) {
            int cmp = a.compareTo(b);
            if (cmp == -1) {
                return b;
            }
            return a;
        }
    }
      

  8.   

    使用方法泛型可以满足你的要求。
    代码大致是:
    public class Max {
    public static   <DataType extends Comparable<DataType>> DataType max(DataType a, DataType b) {
    int cmp = a.compareTo(b);
    if (cmp == -1) {
    return b;
    }
    return a;
    }
    }