Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

to constant or to not

Thread view: 
- - 09 May 2005 14:13 GMT
Some swing classes use a string in the firePorpertyChange method for
instance, JFrame's

firePropertyChange("defaultCloseOperation", oldValue, operation);

Some other classes uses a public constant in replace of the string.

Which way is desired?
Arnaud Berger - 09 May 2005 14:21 GMT
Hi,

There is probably no "desired way" about this.

The only advantage I see for using public constants, is when  you write your
own PropertyChangeListener :

someClass.EVENT_DEFAULT_CLOSE_OPERATION, for instance,  could then be used
by both the firing process and the listener, rather than using a
typo-error-prone string.

Regards,

Arnaud

> Some swing classes use a string in the firePorpertyChange method for
> instance, JFrame's
[quoted text clipped - 4 lines]
>
> Which way is desired?
John McGrath - 11 May 2005 15:52 GMT
> The only advantage I see for using public constants, is when  you write
> your own PropertyChangeListener :
>
> someClass.EVENT_DEFAULT_CLOSE_OPERATION, for instance,  could then be
> used by both the firing process and the listener, rather than using a
> typo-error-prone string.

I use constant (public static final) strings for exactly that reason.  
In my opinion, it is always a good idea to write code in such a way to
decrease the chance of errors.

Signature

Regards,

John McGrath



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.