I have self bounded generic like :
public interface SelfConfigurable<E extends SelfConfigurable<E>> {
E configure(JsonObject settings);
}
And another interface, also with generic type, which extends my previous interface:
public interface ConfigurableSegmentFilter<T> extends SegmentFilter<T>, SelfConfigurable<ConfigurableSegmentFilter<T>> {
}
I also have an implementation like this
public abstract class ConfigurableSegmentFilterSkeleton<T> implements ConfigurableSegmentFilter<T> {
@Override
public ConfigurableSegmentFilter<T> configure(JsonObject settings) {
... }
}
I m instantiating the object through reflection and want to configure it before adding to the List:
List<ConfigurableSegmentFilter<?>> result = ...
ConfigurableSegmentFilter newFilter = Reflection.newInstance() + casting
result.add(newFilter.configure(...)); <-- compile error 'cannot be applien to SelfConfigurable' but why?
//when i call to configure directly i am getting:
SelfConfigurable configure = newFilter.configure(...) <-- why SelfConfigurable??
And am i getting a compile error! It told me that xxx.configure() returns SelfConfigurable interface instead of ConfigurableSegmentFilter, i can't uderstand why its happening.
One more thing, when i am bounding the newFilter with wildcard things starting to work as expected
List<ConfigurableSegmentFilter<?>> result = ...
ConfigurableSegmentFilter<?> newFilter = ... //<-- bound with <?>
result.add(newFilter.configure(...)); <-- No error! But why?
The only difference in ConfigurableSegmentFilter vs ConfigurableSegmentFilter<?>