I thought I was good at Generics, but apparently I didn’t.
Here is a test case for the problem:
import java.util.ArrayList; class Job<J extends Job<J,R>, R extends Run<J,R>> {} class Run<J extends Job<J,R>, R extends Run<J,R>> {} class Job2 extends Job<Job2,Run2> {} class Run2 extends Run<Job2,Run2> {} class RunList<J extends Job<J,R>, R extends Run<J,R>> extends ArrayList<R> {} class Foo {
The compiler does not allow the test1 method described above, saying that "Job" is not within its scope. I kind of understand how it is --- Job , because the raw type does not extend Job<Job,Run> , hence the error. On the contrary, test3 works.
Now, the question is, how do I do this job? I tried # 2, but that does not work either. The problem I assume is really similar to # 1 --- Job<Job,Run> is not within the bounds because its argument of type Job is a raw type.
Does anyone know how to make type checking happy except calling a raw type? Or is it just not achievable in a system like Java?
java generics
Kohsuke kawaguchi
source share