Union with primitive type fields did not work in Java code. This is because the generic Union constructor takes in the initial value as an object, then do a type cast to its proper type. When the field type is primitive, the type cast is not allowed. Eg:

   public NaughtyUnion(
     Field setField,
     Object value
   ) {
     if (value == null)
       throw new NullPointerException("Cannot construct NaughtyUnion with a null value");
     this.setField = setField;
     this.value = (setField == Field.VALUE ? (Naughty) value : null);
     this.field = (setField == Field.FIELD ? (Super) value : null);
     this.id = (setField == Field.ID ? (int) value : null);
   }

 [ERROR] /Users/csong/workspace/scrooge2/scrooge-generator/target/test-sources/thrift/java_def/default/NaughtyUnion.java:[128,44] inconvertible types
 found   : java.lang.Object
 required: int

I think the solution is to get rid of the public generic constructor. Users must call the static constructor methods in order to instantiate a Unoin object of a specific field type

RB_ID=117890
simplify Java union code
This example didn't work for Java
union foo {
  1: BarStruct value
}
because of naming clash: a general "getValue" method was generated and a specific one for the field "value".

I think a lot of the code in union.java is from Apache Thrift's TUnion APIs. Since we don't implement TUnion, I think we can get rid of them.

In the future though, we'll probably make Scrooge types extend TBase. In that case unions do need to implement TUnion. But this decision has not been made, and if it is, the changes would be across the board.

RB_ID=103926