"Unexpected token" using lower-bounded wildcard (Java)
bounded-wildcard, generics, java, syntax-error
Solution
By my reading of the specification, `super` can only be used with a wildcard and can't be captured into a type variable; see JLS 4.5.1. Similarly, `&` is only valid in type variables, not type arguments, and type variables can't use `super`.
After having thought about it, here's my explanation: The reason for a type variable is to eliminate explicit casting to improve type safety. When you declare a type parameter to be `super Foo`, you're saying that it's okay for that parameter to be any superclass of `Foo`. This means that it could be anything up to and including `Object`, and so you have no safe way to presume anything about the objects whose type satisfies that bound, and so there's no information whatsoever contained within a named type variable; you just wildcard it and can call `hashCode()` or `toString()`, but nothing type-specific.
Problem
I have something along the lines of: ``` interface Foo<T> { //... lines [0,45]... /*line 46*/ <R, X super T&R> List<X> weave(R value); //... } ``` But IntelliJ is reporting: - Error:(46, 18) java: > expected - Error:(46, 19) java: illegal start of type - Error:(46, 26) java: '(' expected - Error:(46, 28) java: < identifier > expected - Error:(46, 29) java: 'l' expected - Error:(46, 43) java: < identifier > expected What's the problem? Am I not allowed to bind a name to a lower bound? Or am I only allowed to use a `R&X` expression in an upper bound? Changing it to ``` interface Foo<T> { //... lines [0,45]... /*line 46*/ <R> List<? super T&R> weave(R value); //... } ``` yields - Error(46, 31) java: > expected - Error(46, 32) java: '(' expected - Error(46, 33) java: illegal start of type