With generics, the return type is part of the method signature.
I recently came across this odd behaviour in Java. The JVM has always treated the return type as part of the signature but before Generics Java did not. Here is an example of where it does. This was tested using Oracle JDK 6 update 23, OpenJDK 6 update 20, and IBM's JDK R9 2.4. Apparently Java 5.0 update 22 doesn't not compile this code, but given Java 5.0 is EOL, I would have hoped Java 6 would have the correct behaviour. public class Main {
public static void main(String... args) {
Main.<Integer>print();
Main.<Short>print();
Main.<Byte>print();
Main.<Void>print();
}
public static <T extends Integer> int print() {
System.out.println("here - Integer");
return 0;
}
public static <T extends Short> short print() {
System.out.println("here - Short");
return 0;
}
public static <T extends Byte> byte print() {