Java Generics, extended Generics and abstract classes
Solution 1
public class ProcessImpl<EventType1, EventType2> {
...
}
Because ProcessImpl doesn't extend Process. Your ProcessImpl is not derived from Process, which is what you're declaring that parameter should be.
Solution 2
You might want to do something like this:
public abstract class Process<T, S> {
}
public abstract class Resource<T, S extends Process<T, S>> {
S processor;
}
public class ProcessImpl extends Process<EventType1, ProcessImpl> {
}
public class ResourceImpl extends Resource<EventType1, ProcessImpl> {
}
If you constrain the S
parameter of the Resource
to be a processor you also need to properly declare it on the ProcessImpl
class. I don't know what EventType2
is but it should be implementing Process interface. I assumed you actually want to say ProcessImpl
.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on June 12, 2022Comments
-
Admin about 2 years
I've got the following classes set up:
public abstract class Process<T,S> { ... } public abstract class Resource<T, S extends Process<T, S>> { protected S processer; ... } public class ProcessImpl<EventType1, EventType2> { ... } public class ResourceImpl extends Resource<EventType1, ProcessImpl> { processer = new ProcesserImpl(); ... }
Everything is fine until I get to the
ResourceImpl
. I'm told thatProcessImpl
is not a valid substitute for the bounded parameter<S extends Process<T,S>>
of the typeResource<T,S>
.I've tried various ways of getting around this and keep hitting a wall.
Does anyone have any ideas?