Skip to content

Instantly share code, notes, and snippets.

@taku0
Last active June 15, 2016 11:59
Show Gist options
  • Save taku0/4335f65eb20a54fb965fff58fd582878 to your computer and use it in GitHub Desktop.
Save taku0/4335f65eb20a54fb965fff58fd582878 to your computer and use it in GitHub Desktop.
interface Z {}
interface N<T> {}
interface E<T> extends N<N<? super E<? super T>>> {}
// Changing E to the following, Oracle JDK 1.8.0_92 says
// `error: incompatible types: E<Z> cannot be converted to N<? super E<Z>>`
// interface E<T> extends N<N<? super E<T>>> {}
class GenericsLoop {
N<? super E<Z>> doit(E<Z> v) {
/*
E → NNE
EZ <: NEZ
NNEZ <: NEZ
EZ <: NEZ
*/
return v;
}
}
interface Z {}
interface N<T> {}
interface E<T> extends N<N<? super E<N<T>>>> {}
class Main {
N<? super E<Z>> doit(E<Z> v) {
/*
E → NN?EN
EZ <: N?EZ
NN?ENZ <: N?EZ
EZ <: N?ENZ
NN?ENZ <: N?ENZ
ENZ <: N?ENZ
↓*
ENNZ <: N?ENNZ
↓*
ENNNZ <: N?ENNNZ
.
.
.
*/
return v;
}
}
trait Z
trait N[T]
// error: illegal cyclic reference involving trait E
trait E[T] extends N[N[_ >: E[N[T]]]]
class Main {
def doit(v: E[Z]): N[_ >: E[Z]] = v
}
trait Z
trait N[-T]
// error: class graph is not finitary because type parameter T is expansively recursive
trait E[-T] extends N[N[E[N[T]]]]
class Main {
def doit(v: E[Z]): N[E[Z]] = v
}
trait Z
trait N[-T]
trait E[-T] extends N[N[E[_ >: T]]]
class Main {
def doit(v: E[Z]): N[E[Z]] = v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment