You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by David Zejda <dv...@atlas.cz> on 2004/07/24 07:58:47 UTC

little suggestion about "instanceof"

I think, it would be better to use something like

((source != null) && (source.getClass()==Calendar.class))
{
     ...

in conversion strategies than

if (source instanceof Calendar)
{
     ...

to avoid reducing e.g. custom Calendar subclass to Calendar during 
conversion.

David

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: little suggestion about "instanceof"

Posted by David Zejda <dv...@atlas.cz>.
Thanks for a suggestion!

There is a nice article, where (in the second part) the result of 
improper instanceof check in inheritance hierarchy is demonstrated.

http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html

David

Jakob Braeuchi wrote:

> hi david,
> 
> the instanceof is some kind of standard implemenation for equals(). see 
> Effective Java by Josh Bloch.
> 
> jakob
> 
> David Zejda schrieb:
> 
>> I think, it would be better to use something like
>>
>> ((source != null) && (source.getClass()==Calendar.class))
>> {
>>     ...
>>
>> in conversion strategies than
>>
>> if (source instanceof Calendar)
>> {
>>     ...
>>
>> to avoid reducing e.g. custom Calendar subclass to Calendar during 
>> conversion.
>>
>> David
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: little suggestion about "instanceof"

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi david,

the instanceof is some kind of standard implemenation for equals(). see 
Effective Java by Josh Bloch.

jakob

David Zejda schrieb:

> I think, it would be better to use something like
> 
> ((source != null) && (source.getClass()==Calendar.class))
> {
>     ...
> 
> in conversion strategies than
> 
> if (source instanceof Calendar)
> {
>     ...
> 
> to avoid reducing e.g. custom Calendar subclass to Calendar during 
> conversion.
> 
> David
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: little suggestion about "instanceof"

Posted by David Zejda <dv...@atlas.cz>.
Guillaume Nodet wrote:

> Maybe for the GregorianCalendar as Calendar is an abstract class...
> You really use a custom calendar class ?

No, I don't. I only looked on convstrategies to get a bit of inspiration 
for my own ones and noticed that..

> Just for curiosity what is the purpose of you own calendar class ?

from Calendar apidoc:
Subclasses of Calendar interpret a Date  according to the rules of a 
specific calendar system. The platform provides one concrete subclass of 
Calendar: GregorianCalendar. Future subclasses could represent the 
various types of lunar calendars in use in many parts of the world.

..so there are more calendars planned in JDK and also there is no 
guarantee, that there are no other custom subclasses yet.

I think it's a general rule, to take into accout subclasses, everywhere 
applicable (~ not final classes), esp. in tools, libraries, frameworks...

David

> Guillaume
> 
>>-----Message d'origine-----
>>De : David Zejda [mailto:dvid@atlas.cz]
>>Envoye : samedi 24 juillet 2004 07:59
>>A : OJB Users List
>>Objet : little suggestion about "instanceof"
>>
>>
>>I think, it would be better to use something like
>>
>>((source != null) && (source.getClass()==Calendar.class))
>>{
>>     ...
>>
>>in conversion strategies than
>>
>>if (source instanceof Calendar)
>>{
>>     ...
>>
>>to avoid reducing e.g. custom Calendar subclass to Calendar during 
>>conversion.
>>
>>David


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RE: little suggestion about "instanceof"

Posted by Guillaume Nodet <gu...@deliasystems.com>.
Maybe for the GregorianCalendar as Calendar is an abstract class...
You really use a custom calendar class ?
Just for curiosity what is the purpose of you own calendar class ?

Guillaume

> -----Message d'origine-----
> De : David Zejda [mailto:dvid@atlas.cz]
> Envoye : samedi 24 juillet 2004 07:59
> A : OJB Users List
> Objet : little suggestion about "instanceof"
> 
> 
> I think, it would be better to use something like
> 
> ((source != null) && (source.getClass()==Calendar.class))
> {
>      ...
> 
> in conversion strategies than
> 
> if (source instanceof Calendar)
> {
>      ...
> 
> to avoid reducing e.g. custom Calendar subclass to Calendar during 
> conversion.
> 
> David
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org