1

I am reading records from Excel to a POJO
I have created an enum to hold the order of each column

My question is Is it possible to save the column type as well?

so later I will pass this enum to some method it will know how to process the value based on its type...

for example:

public enum StudentInfo{
 name(0,String),
 age(1,Integer),
 height(2,Float),
 eyeColor(5,Color);
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159

1 Answers1

3

You can save the class of the expected type as a field in the enum instances. You would construct them similarly to what you have now but like:

name(0, String.class),

Then you can have a

private Class<?> columnType;

as a field and use that.

As an aside, by convention (see here and here), enum values are usually named in all upper case.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Javier C
  • 726
  • 5
  • 15