First, I have a simple template, nothing fancy:
public abstract class ListOfK<K> {
private List<K> insides = new ArrayList<>();
}
Next, I'm creating a service interface using the template
public abstract interface SomeService<K extends ListOfK<K>> {
int calculateSomething (K input);
int calculateAnother (ListOfK<K> list);
}
So far so good with the abstraction.
Now, let's get to the implementation
public class ListOfString extends ListOfK<String> {
}
and implementation of SomeService:
public class SomeServiceImpl extends SomeService<String> {
@Override
public int calculateSomething(String input) {
return 0; // TODO impl
}
@Override
public int calculateAnother(ListOfK listOfK) {
return 0; // TODO impl
}
}
Somehow, when SomeServiceImpl
extends SomeService<String>
, it marks Type parameter java.lang.String is not within its bound; should extend ListOfK<String>
What should I input as implementation of SomeService
so it doesn't give error? Or do I make mistake with SomeService? I just want a class whom input is a another class using Generic.
Thanks in advance.