Skip to content

Instantly share code, notes, and snippets.

@asajeffrey
Created November 11, 2016 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asajeffrey/512977df4d1d4d720160187421f4a86b to your computer and use it in GitHub Desktop.
Save asajeffrey/512977df4d1d4d720160187421f4a86b to your computer and use it in GitHub Desktop.
Checking whether type inference in Java will allow cyclic inferred types; comples with jdk 1.7 but not 1.6.
abstract class Nope<T extends Nope<T>> {
private Nope() {}
}
class NopeElim {
public<T extends Nope<T>> void ohNo() {
System.out.println("Is there a way to call this");
}
}
public class TestCyclicTypeInference {
public static void main (String[] args) {
NopeElim elim = new NopeElim();
// Can you find a T such that elim.<T>ohNo() typechecks?
// No, but this does:
elim.ohNo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment