I need to create a class which offers a variable amount of fields. These fields might be String or int.
Example:
myObject1 might have as fields:
description - String
idNumber - int
authorName - String
myObject2 might contain
description - String
idNumber - int
authorName - String
year - int
myObject1 and myObject2 should be objects of the same class.
This needs to be completely transparant. I should be able to get the values using:
myObject.getVal ue("description ") ... which should return a string
myObject.getVal ue("year") ...which should return an integer
I assume the underlying datastructure should have a hashmap-like structure, so I can map the name of the field to it's value, however, I seem to be unable to figure out how let getValue return an String in the first case, and an Integer in the second.
note that I do not want to return Object. I want to have a clear distinction between String or integer. I have no clue which fields might occur, or how many string-fields or int-fields it might have.
any help would be appreciated.
Thanks
Example:
myObject1 might have as fields:
description - String
idNumber - int
authorName - String
myObject2 might contain
description - String
idNumber - int
authorName - String
year - int
myObject1 and myObject2 should be objects of the same class.
This needs to be completely transparant. I should be able to get the values using:
myObject.getVal ue("description ") ... which should return a string
myObject.getVal ue("year") ...which should return an integer
I assume the underlying datastructure should have a hashmap-like structure, so I can map the name of the field to it's value, however, I seem to be unable to figure out how let getValue return an String in the first case, and an Integer in the second.
note that I do not want to return Object. I want to have a clear distinction between String or integer. I have no clue which fields might occur, or how many string-fields or int-fields it might have.
any help would be appreciated.
Thanks
Comment