Skip to content
Advertisement

How to write this method in a generic way in java

Currently, I have this method implemented for five different class to configure FlatFileReader for five different text files and load into DB table.

I would like to know is there a way to implement this method in a common place So that my each file will call this method to configure my reader to read their corresponding files..

Every file will send different entity class to load their file. like Primary Entity, ChildEntity1, ChildEntity2, ChildEntity3, ChildEntity4.

JavaScript

Advertisement

Answer

Add generics to the method

JavaScript

If you want to limit the usage only to the listed entities, create a common interface Entity that is implemented by all concrete entities (PrimaryEntity, ChildEntity1, ChildEntity2, ChildEntity3, ChildEntity4) and change the signature to

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement