@ SuppressWarnings ( "unchecked" ) public static < E > E createRecord ( Class < E > type , Schema schema ) { // Don't instantiate SpecificRecords or interfaces. if ( isGeneric ( type ) && ! type . isInterface ( ) ) { if ( GenericData . Record . class . equals ( type ) ) { return ( E ) GenericData . get ( ) . newRecord ( null , schema ) ; } return ( E ) ReflectData . newInstance ( type , schema ) ; } return null ; }
If E implements GenericRecord but does not implement SpecificRecord then create a new instance of E using reflection so that GenericDataumReader will use the expected type .