/* Author : Michael Robinson Program : genericMethods.java Purpose : To present generic methods that accept any type of data Updated : July 28th, 2099 */ public class genericMethods { public static void showMe( T[] multiDataType ) { for( T elements : multiDataType ) { System.out.printf( "%s ", elements ); } System.out.println(); }//end public static void showMe( T[] multiDataType ) /* generic return method use only objects that: inherits from returns method name Comparable generic accepting genetic data T data a, c, and c */ public static < T extends Comparable > T maxMethod( T firstItem, T middleItem, T lastItem ) { System.out.printf( "The max value of %s %s %s is ", firstItem, middleItem, lastItem ); T maximum = firstItem; if( middleItem.compareTo( maximum ) > 0 ) { maximum = middleItem; } if( lastItem.compareTo(maximum) > 0 ) { maximum = lastItem; } return maximum; }//end public static < T extends Comparable > T maxMethod( // T firstItem,T middleItem,T lastItem ) public static void main( String arg[] ) { Object ob[] = { "one", 2, 2.5, "last" }; showMe( ob ); Integer In[] = { 1, 2, 3, 4, 5 }; showMe( In ); Double Dou[] = { 1.1, 2.2, 3.3, 4.4 }; showMe( Dou ); String St[] = { "Joe", " goes", " to", " FIU" }; showMe( St ); Character Ch[] = { 'a', 'b', 'c', 'd', 'e' }; showMe( Ch ); System.out.println( maxMethod( "one", "four", "three" ) ); System.out.println( maxMethod( 188, 103, 44 ) ); }//end public static void main( String arg[] ) }//end public class genericMethods