Is this just a general enquiry or do you think you have a use for such a thing ?
If the latter it might be better to explain what you are trying to do and then maybe someone will be able to suggest a solution.
I do need to use it. I am actually reading a file which can be of either xls or xlsx format. We have one API each for rendering xls and xlsx file. For xls it's HSSFWorkbook and for xlsx it's XSSFWorkbook. Both these classes have methods with same names in it. So if I can have a synonym type, I can use it to declare either HSSFWorkbook or XSSFWorkbook variable as the case may be.
The way you would usually do that in Java would be to have an interface that defines the operations, and two classes that implement the interface. You then declare the variable using the interface type.
In this case, both HSSFWorkbook and XSSFWorkbook implement the Workbook interface. You should really be coding to the Workbook interface instead of the implementation classes.
Harish V Gupta wrote:I do need to use it. I am actually reading a file which can be of either xls or xlsx format. We have one API each for rendering xls and xlsx file. For xls it's HSSFWorkbook and for xlsx it's XSSFWorkbook. Both these classes have methods with same names in it. So if I can have a synonym type, I can use it to declare either HSSFWorkbook or XSSFWorkbook variable as the case may be.
Seems to me like a basic class hierarchy rather than a typedef, even in C++; but it has been quite a while. In Java, if it was me, I'd probably base it around a WorkBook interface, as already mentioned.