perhaps this exaplanation will help:
http://stackoverflow.com/q
public static <AnyType> AnyType findMax( AnyType[] arr)
{
int maxIndex = 0;
for(int i=1; i<arr.length; i++)
if(arr[i].compareTo(arr[maxIndex]) > 0)
maxIndex = i;
return arr[maxIndex];
}
public static <T extends Comparable<T>> T findMax( T[] arr)
{
int maxIndex = 0;
for(int i=1; i<arr.length; i++)
if(arr[i].compareTo(arr[maxIndex]) > 0)
maxIndex = i;
return arr[maxIndex];
}
public static <AnyType extends Comparable<AnyType>> AnyType findMax( AnyType[] arr)
{
int maxIndex = 0;
for(int i=1; i<arr.length; i++)
if(arr[i].compareTo(arr[maxIndex]) > 0)
maxIndex = i;
return arr[maxIndex];
}
public static <AnyType extends Comparable> AnyType findMax( AnyType[] arr)
{
int maxIndex = 0;
for(int i=1; i<arr.length; i++)
if(arr[i].compareTo(arr[maxIndex]) > 0)
maxIndex = i;
return arr[maxIndex];
}
public class Box<T> {
private T t; // T stands for "Type"
public void setEntity(T t) {
this.t = t;
}
public T getEntity() {
return t;
}
}
arr[i].compareTo(arr[maxIndex])
is defined because element of array arr is isntance of T, therefore compiler needs just this way <T extends Comparable<T>> and thisTitle | # Comments | Views | Activity |
---|---|---|---|
Issues installing SSL certificate into Apache Tomcat | 3 | 70 | |
mapShare challenge | 13 | 66 | |
@SBGen Method | 3 | 25 | |
how do i compare an object based on two fields | 6 | 26 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
11 Experts available now in Live!