Avro
  1. Avro
  2. AVRO-298

Dynamic and Specific APIs could be generified for better type safety

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.0
    • Component/s: java
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      Jon Hsieh pointed out that ReflectDatumWriter always returned a DatumWriter<Object>, though it's often clear (by the way the schema is constructed) that there's a more specific type that could be used. In the quote below, the second line would be preferable to the third.

        Schema schema = reflectData.getSchema(MyObject.class);
        // DatumWriter<MyObject> writer = new ReflectDatumWriter(schema);
        DatumWriter<Object> writer = new ReflectDatumWriter(schema);
      
      1. AVRO-298.patch.txt
        20 kB
        Philip Zeyliger

        Activity

        Hide
        Philip Zeyliger added a comment -

        Attaching a patch which adds generics to

        {Specific,Reflect}

        Datum

        {ReaderWriter}

        . If the DatumWriter interface is parameterized, as it is, this seems like the right thing. My test for this was iterating until "ant clean compile-java compile-test-java" didn't show any warnings; the type-erased code is identical, I believe.

        I suspect that the Requestor hierarchy might need similar treatment, but one at at time.

        Show
        Philip Zeyliger added a comment - Attaching a patch which adds generics to {Specific,Reflect} Datum {ReaderWriter} . If the DatumWriter interface is parameterized, as it is, this seems like the right thing. My test for this was iterating until "ant clean compile-java compile-test-java" didn't show any warnings; the type-erased code is identical, I believe. I suspect that the Requestor hierarchy might need similar treatment, but one at at time.

          People

          • Assignee:
            Philip Zeyliger
            Reporter:
            Philip Zeyliger
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development