Created
November 11, 2016 00:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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