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

  • SEARCH
  • Home
  • 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 786193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:00:06+00:00 2026-05-14T21:00:06+00:00

I’m using Eclipse, and it is perfectly happy with the following code: public interface

  • 0

I’m using Eclipse, and it is perfectly happy with the following code:

public interface MessageType
{
    public static final byte   KICK     = 0x01;
    public static final byte   US_PING  = 0x02;
    public static final byte   GOAL_POS = 0x04;
    public static final byte   SHUTDOWN = 0x08;
    public static final byte[] MESSAGES = new byte[] {
        KICK,
        US_PING,
        GOAL_POS,
        SHUTDOWN
    };
}

public class MessageTest implements MessageType
{
    public static void main(String[] args)
    {
        int b = MessageType.MESSAGES.length;    //Not happy
    }
}

However, the platform that I’m running it on crashes at the line marked above. By crash, think an equivalent of a BSOD. Is there anything wrong with my code, or do I need to pursue the developers of the Java VM for my platform?


EDIT:

Ok, thanks for your responses. It turned out to be a bug in the Java VM. To quote the developer, ‘gloomyandy’,

This is a known problem with interfaces that have a static initializer. It is fixed in the current development builds…

  • 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-05-14T21:00:07+00:00Added an answer on May 14, 2026 at 9:00 pm

    I don’t see any problem with this code, other than that if you are using Java5 or above, you would be better off using an enum:

    public enum MessageType
    {
        KICK     (0x01),
        US_PING  (0x02),
        GOAL_POS (0x04),
        SHUTDOWN (0x08);
    
        private byte value;
        MessageType(byte value) { this.value = value; }
        byte getValue() { return value; }
    }
    
    public class MessageTest
    {
        public static void main(String[] args)
        {
            int b = MessageType.values().length;    //Should be happy :-)
        }
    }
    

    Update: to recreate the enum value from its byte representation, you need to supplement MessageType with the following (adapted from Effective Java, 2nd Ed. Item 31):

    private static final Map<Byte, MessageType> byteToEnum = new HashMap<Byte, MessageType>();
    
    static { // Initialize map from byte value to enum constant
      for (MessageType type : values())
        byteToEnum.put(type.getValue(), type);
    }
    
    // Returns MessageType for byte, or null if byte is invalid
    public static MessageType fromByte(Byte byteValue) {
      return byteToEnum.get(byteValue);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What I've done in my own project to solve the… May 15, 2026 at 3:11 pm
  • Editorial Team
    Editorial Team added an answer I am a recent Computer Science graduate and from my… May 15, 2026 at 3:11 pm
  • Editorial Team
    Editorial Team added an answer Yes and no. It roughly works the same as in… May 15, 2026 at 3:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.