John Keane's Profile

About

 
Points: 0

Pages

Contact

 

John Keane
June 11, 2016 · Public

Hi Bucky.
I have a question on your video (Intermediat Java Tutorial - 19 Generic Return Types)
(I have copied the code below)

Basically i don't understand how the string "tots" is deemed the 'max' over "apples" and "chicken" using 'compateTo'.
What values is it using to compare one string against another ?
Thanks
John


import java.util.*;
public class bucky {
public static void main(String[] args) {

System.out.println(max(23,42,1));
System.out.println(max("apples","tots","chicken"));
} // end main method

public static T max(T a, T b, T c){
T m = a;

if(b.compareTo(a) > 0)
m = b;

if(c.compareTo(m) > 0)
m = c;

return m;

} // end generic method
} // end class bucky

John Keane
May 12, 2015 · Public

Java
869 Followers