SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
But there is bound to be a better way to do things than instanceof, which is usually another “code small”. I would start by no longer using java.util.Date or Calendar.Rob Spoor wrote:. . . instanceof and casting is a much nicer way than using reflection.
Ron McLeod wrote:Do you want to know what type of object was passed to your method?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
I agree with Rob that you have some very dubious design there.Fred Victa wrote:. . . I would like to find out if the Person object has any properties of type Date or Calendar.
Ron McLeod wrote:You can use reflection to inspect the fields for their type:
Rob Spoor wrote:What do you need to do with these properties?
Fred Victa wrote:
Suppose the properties are private. If the field is of type Date or Calendar and it is not null, how can I convert the timestamp to UTC?
Fred Victa wrote:
Rob Spoor wrote:What do you need to do with these properties?
If they are of type Date or Calendar and they are not null, then convert the timestamp to UTC.
The properties are private.
Paul Clapham wrote:
Or if you just have a specific list of classes you're interested in here, let's bring up the idea of making those classes implement a specific interface again.