I have this interface
public interface CopyData {
<T extends SpecificRecordBase> void copy(T data);
}
I have class implementing this interface
public class CopyDataImpl implements CopyData {
private CopyDataProvider copyDataProvider;
@Override
public <T extends SpecificRecordBase> void copy(T data) {
try {
Copier copier = copyDataProvider.copyFor(data);
if(copier == null) {
return;
}
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
Encoder encoder = EncoderFactory.get().jsonEncoder(data.getSchema(), byteStream);
data.customEncode(encoder);
encoder.flush();
copier.copy(data);
} catch (Exception e) {
log.error("Error occurred storing the data {}", e.getMessage());
}
}
}
I am using Spring and loading their beans respectively.
@Configuration
public class CopyDataDynamicConfig {
@Bean
public CopyDataProvider copyDataProvider() {
return new CopyDataProviderImpl();
}
@Bean
public CopyData copyData(CopyDataProvider copyDataProvider) {
return new CopyDataImpl(copyDataProvider);
}
}
I want to make my interface a functional interface and use it. Is it feasible or an overkill in this case?
Can someone please share how I can achieve that?
EDIT 1
I am aware that I can make my interface functional interface easily as it has only method and can add @FunctionalInterface
annotation.
My question was I want to use functional interface directly and not using dedicated implementation class.