Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8874575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:45:22+00:00 2026-06-14T18:45:22+00:00

I have a Java problem here. I have many constants, which are consecutive constant

  • 0

I have a Java problem here. I have many constants, which are consecutive constant integers, currently defined like:

interface Flags {
  static final short A = 0;
  static final short B = A + 1;
  static final short FIRST_USER_FLAG = B + 1;
}

Many of you would now recommend me to use Enum. The problem is, I need more than one place with those flags. So it would be like:

interface CustomFlags {
  static final short USER_A = Flags.FIRST_USER_FLAG + 1;
  static final short USER_B = USER_A + 1;
}

The code you see here, also has to be the same on two sides of network, included in server code and client code. Every message between those has defined it’s flag and by this flag, the networking creates message object, registered with this flag. This doesn’t seem to be the best approach, but I couldn’t think of anything better. And the problem is, that the networking code has its own flags and messages, which does some basic authentication and handshaking. And then there has to be messages (and their flags) defined by the code that uses the networking.

My question is, how to make this more maintainable and readable? Also, if there’s anyone, who knows about better approach to send and recreate messages (I’m using both TCP and UDP, depends on the message), I would be really thankful to hear it.

If there’s something I didn’t explain, please let me know and I’ll add it.

PS: Sorry for my bad english, as I’m not native speaker.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:45:23+00:00Added an answer on June 14, 2026 at 6:45 pm

    I would leave it the way it is. That’s quite a usual technique for defining constants of a protocol. If the peer isn’t Java I would probably ‘de-engineer’ a bit further, and just define the names and their values directly without worrying about the arithmetic. You don’t want this to be easy to change, you actually want it to be impossible to change, so that inadvertent protocol incompatibilities don’t creep in. Enums are for cases where you are more interested in the names and in type safety and not too concerned about the actual values, ordinals, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a specific java client library. Here is the situation:
I'm new here and kinda new to java. I've encountered a problem. I have
Here is my problem: I have many known locations (I have no influence to
We have a Java Swing application which contains components like JTable, JCombobox, JTextArea and
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
So I have a strange problem, I have a java swing application that has
So I have a problem where Java is telling me that the following line
So I have a bit of a performance problem. I have made a java
I've run into an rather irritating problem in java. I have a program that
Good evening ladies and gentlemen, I have a problem with Java Swing that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.