• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code conventions and constants variables

 
Wojtek Polczynski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a dilemma how the name of constant fields should look like.

In the LockManager class I need a field that holds information about currently locked records. I would like to declare it as a Map and call this field ´┐ŻlockedRecords´┐Ż.

Could you pleas tell me how this field should be declared?

a) private static final Map LOCKED_RECORDS = new HashMap();
b) private static final Map lockedRecords = new HashMap();

On the one hand I found in the "Java code conventions" guide an information saying that "The names of variables declared class constants should be all uppercase." On the other hand calling the method in the following way...

LOCKED_RECORDS.wait();

...looks really strange to me.

Can anyone clear it up for me?

Thanks,
Wojtek
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a) private static final Map LOCKED_RECORDS = new HashMap();
b) private static final Map lockedRecords = new HashMap();


Hi Wojtek,

Definitely a: constants are indeed always in upper case. This may look strange when the constant is an object, which' state can still change, but this is the correct way.

However, you might consider making it non-final and then you should make it like:

private static Map lockedRecords = new HashMap();

That looks less strange.

Frans.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic