I am learning Java generic from: https://docs.oracle.com/javase/tutorial/java/generics/bounded.html and I have some doubts on the code sample below:
public class Box<T> {
private T t;
public void set(T t) {
this.t = t;
}
public T get() {
return t;
}
public <U extends Number> void inspect(U u) {
System.out.println("T: " + t.getClass().getName());
System.out.println("U: " + u.getClass().getName());
}
public static void main(String[] args) {
Box<Integer> integerBox = new Box<Integer>();
integerBox.set(new Integer(10));
integerBox.inspect("some text"); // error: this is still String!
}
}
Why wasnt the inspect() method to be written as shown below instead it was ?
public <T extends Number> void inspect(T t) { }
There are some other code samples which has the following syntax. What does the 1st pair stands for?
public <K,V> SomeClass<K,V>
What does static stands for?
public static <T> int countGreaterThan(T[] anArray, T elem)