-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Using static Strings in annotations
PostPosted: Thu Nov 01, 2007 6:41 am 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
Hi,
If I am using the same String in a few annotations, are my better off defining that String as a static constant.
For example, suppose I use:

@OrderBy("primaryKey ASC")

in several places, should I do:

final static String PRIMARY_KEY_ASC = "primaryKey ASC".

and then

@OrderBy(PRIMARY_KEY_ASC)

My guess is that there is no memory saving here as in the former approach hibernate will treat the String as a literal. However, I may prevent some silly start up errors.

The examples use the former approach, so I fear I may be being pedantic here.

Any thoughs?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 7:52 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
The latter approach is generally preferred as a programming practice overall.
It's easier to fix bugs that way as well (if you'd made a typo in the string one annotation and copied that a hundred times for example...).

It won't matter at runtime, as the compiler (if you declare the String as static final at least) will evaluate the expression and pull in the String literal for each place it is used.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.