Question 5
Consider the Java code given below.
public class MathUtils { public <T> T getFirst(T[] arr) { // Returns the first element of the array }
public <T extends Number> double sum(T[] arr) { // Returns the sum of all elements in the array }}How does class MathUtils look after type erasure?
public class MathUtils {
public Object getFirst(Object[] arr) {
// Returns the first element of the array
}
public double sum(Object[] arr) {
// Returns the sum of all elements in the array
}
}public class MathUtils {
public Object getFirst(Object[] arr) {
// Returns the first element of the array
}
public double sum(Number[] arr) {
// Returns the sum of all elements in the array
}
}public class MathUtils {
public T getFirst(T[] arr) {
// Returns the first element of the array
}
public double sum(T[] arr) {
// Returns the sum of all elements in the array
}
}public class MathUtils {
public Object getFirst(Object[] arr) {
// Returns the first element of the array
}
public double sum(Double[] arr) {
// Returns the sum of all elements in the array
}
}