Search:

Type: Posts; User: copeg

Search: Search took 0.12 seconds.

  1. Re: Help, Want to make a BASIC min value Method with Generics

    You could rely on the fact that the primitive wrappers all implement the Comparable interface...

    public static Comparable min(Comparable c1, Comparable c2){
    return c1.compareTo(c2) < 0 ? c1 :...
  2. Re: Help, Want to make a BASIC min value Method with Generics

    Just use the Math class

    int i1 = 5;
    int i2 = 10;
    float f1 = 1.0;
    float f2 = 5;
    double d1 = 1;
    double d2 = 10;
    System.out.println(Math.min(i1,i2));
    System.out.println(Math.min(f1,f2));
  3. Re: Help, Want to make a BASIC min value Method with Generics

    Why use generics then? Do you want to compare primitives or objects? To compare intergers, just pass primitives:

    int min(int val1, int val2){
    return val1 < val2 ? val1 : val2;
    }

    Or just use...
Results 1 to 3 of 3