title: cast byte to enum
body: <p>I have the following code: </p>
  
  <pre><code>
  public enum PortableTypes { Boolean, etc...};
  
  public void testConversion() {
    byte b = 5;
    PortableTypes type = (PortableTypes)b;
  }
  </code></pre>
  
  <p>When I compile, I am told that these are inconvertible types. I was unaware that something as simple as this would be left out of java. Am I missing something, or does Java just not support casting into an enum at all? I tested with an int as well, and it failed. </p>
  
  <p>If this is not supported, what is the easiest workaround?</p>
  
  <p>EDIT:</p>
  
  <p>Since everyone keeps complaining about "bad design", I'll explain a little further. I am using an enum to represent the types that you can send using my TcpServer. The packet is sent with this type, and on the receiving side I look at the type and use it to convert the bytes that are read from the packet into usable data. Obviously you can't send an enum using an OutputStream, so I need to convert the enum value into a numerical value to be sent. I disagree with the idea that this is "bad design", I think that Enums are indeed supposed to be used for exactly this purpose, but that this design does not work in Java because it is strongly typed. </p>