fork download
  1. class MAIN {
  2. public static void main (String[] args) {
  3. System.out.println((new A()).getThis());
  4. System.out.println((new B()).getThis());
  5. }
  6. }
  7. class A {
  8. public<T extends A> T getThis() {
  9. return this;
  10. }
  11. }
  12. class B extends A {}
Compilation error #stdin compilation error #stdout 0.06s 380224KB
stdin
Standard input is empty
compilation info
Main.java:9: error: incompatible types
		return this;
		       ^
  required: T
  found:    A
  where T is a type-variable:
    T extends A declared in method <T>getThis()
1 error
stdout
Standard output is empty