public class CSVParser {
protected <T extends Message> void addMessageToResult(Message message, Descriptor descriptor, ImmutableList.Builder<T> messageListBuilder) {
. . .
}
For DynamicMessage I wanted to have a different handling so I tried
public class CSVParserDynamicMessage extends CSVParser {
protected<DynamicMessage> void addMessageToResult(Message message, Descriptor descriptor, ImmutableList.Builder<DynamicMessage> messageListBuilder) {
messageListBuilder.add(DynamicMessage.parseFrom(descriptor, message.toByteString()));
}
But it gives the compilation error
'addMessageToResult(Message, Descriptor, Builder)' in 'com.google.cloud.verticals.telco.taap.dataflow.dataingestion.common.parsers.CSVParserDynamicMessage' clashes with 'addMessageToResult(Message, Descriptor, Builder)' in 'com.google.cloud.verticals.telco.taap.dataflow.dataingestion.common.parsers.CSVParser'; both methods have same erasure, yet neither overrides the other
I'm having to do the ugly method below (haven't yet attempted to run and see if it actually works):
@Override
protected<T extends Message> void addMessageToResult(Message message, Descriptor descriptor, ImmutableList.Builder<T> messageListBuilder)
throws InvalidProtocolBufferException {
messageListBuilder.add((T) DynamicMessage.parseFrom(descriptor, message.toByteString()));
}
Note that my attempt of subclassing was inspired from Java generics (template) specialization possible (overriding template types with specific types) but the difference seems to be that in my case the template paramter T doesn't exist at class level but only at method level. I'm not able to understand why it doesn't work for my usecase.
Any ideas are much appreciated.