Skip to content

Instantly share code, notes, and snippets.

@taku0
Last active Jun 15, 2016
Embed
What would you like to do?
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