generics - "Unexpected token" using lower-bounded wildcard (Java) -


i have along lines of:

interface foo<t> {     //... lines [0,45]...  /*line 46*/ <r, x super t&r> list<x> weave(r value);     //... } 

but intellij reporting:

  1. error:(46, 18) java: > expected
  2. error:(46, 19) java: illegal start of type
  3. error:(46, 26) java: '(' expected
  4. error:(46, 28) java: < identifier > expected
  5. error:(46, 29) java: 'l' expected
  6. error:(46, 43) java: < identifier > expected

what's problem? not allowed bind name lower bound? or allowed use r&x expression in upper bound?

changing to

interface foo<t> {     //... lines [0,45]...  /*line 46*/ <r> list<? super t&r> weave(r value);     //... } 

yields

  1. error(46, 31) java: > expected
  2. error(46, 32) java: '(' expected
  3. error(46, 33) java: illegal start of type

by reading of specification, super can used wildcard , can't captured type variable; see jls 4.5.1. similarly, & valid in type variables, not type arguments, , type variables can't use super.

after having thought it, here's explanation: reason type variable eliminate explicit casting improve type safety. when declare type parameter super foo, you're saying it's okay parameter any superclass of foo. means , including object, , have no safe way presume objects type satisfies bound, , there's no information whatsoever contained within named type variable; wildcard , can call hashcode() or tostring(), nothing type-specific.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -