The basic idea is that I have an interface that transforms data into different data, and I want to use this interface to transform a specific subset of data.
public static interface Data<D> {
// transform the data into different data
<T> Data<T> transform(Function<D,T> transformer);
}
// "Something" that has been labeled
public static interface Labeled {
String getLabel();
}
// class intended to use the Data<D> interface to transform labeled data specifically
public static class LabeledData<L extends Labeled> implements Data<L> {
public final L labeledData;
public LabeledData(L labeledData) {
this.labeledData= labeledData;
}
// of course this will not compile because it does not override
// <T> Data<T> transform(Function<D,T> transformer);
@Override
public <T extends Labeled> LabeledData<T> transform(Function<L,T> transformer) {
return new LabeledData<>(transformer.apply(labeledData));
}
}
Is there anyway to either redeclare Data.transform or rearrange LabeledData to acomplished the desired functionality and flow?
I understand I "could" create LabeledData.transformLabled(...) and define the original transform to somehow cast to LabledData or throw an exception, but that doesn't sound like a very good solution.
I could also pass in a T LabeledData<L extends Labeled, T extends Labeled> but I think that would limit the usage to one trasnform type at a time, unless there is some creative way to do it.
class Data<D, B> { <T extends B> Data<T> transform(Function<D, B> transformer), but I'm not sure that'd work.