[ 
https://issues.apache.org/jira/browse/AVRO-2918?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17739660#comment-17739660
 ] 

Christophe Le Saec commented on AVRO-2918:
------------------------------------------

For generated code, i have an issue with static method, as {_}Java enforce 
return type compatibility for overridden *static* methods{_}.
This means this code *does not compile*
{code:java}
public class Person {
  public static Integer value() {  return 2; }
}

public class Employee extends Person {
  public static String value() {  return "Two"; }
}
{code}
because String is not a subclass of Integer.

So, in code, it's a problem for methods :
{code:java}
public static BinaryMessageEncoder<Person> getEncoder() 
public static BinaryMessageEncoder<Person> getDecoder() 
public static BinaryMessageDecoder<Person> createDecode(SchemaStore resolver) {
public static Person.Builder newBuilder()
{code}
that has same for Employee.

As a workarround, i can rename this methods:
{code:java}
public static BinaryMessageEncoder<Person> getEncoderPerson() 
public static BinaryMessageEncoder<Employee> getEncoderEmployee() 
{code}
...
it works, but lead to uncompatible change.

> Schema polymorphism
> -------------------
>
>                 Key: AVRO-2918
>                 URL: https://issues.apache.org/jira/browse/AVRO-2918
>             Project: Apache Avro
>          Issue Type: New Feature
>          Components: logical types, misc, spec
>            Reporter: Jonathan Rapoport
>            Assignee: Christophe Le Saec
>            Priority: Critical
>              Labels: features, pull-request-available
>   Original Estimate: 96h
>          Time Spent: 10m
>  Remaining Estimate: 95h 50m
>
> Include the option to use named types as base types for a new schema. Allow 
> for MRO generation. Field inheritance. 
> The benefits of this approach include:
>  * Defining a schema as validation for a certain wire, and so allowing the 
> receiver to be certain of the structure of the data (this works today). 
> However, defining an extension of this schema, or certain schemas which can 
> be normalized to the original schema, but contain additional information, 
> will not allow it to be sent over the same wire.
>  * Backwards compatibility through inheritance - you never break the old 
> schema, thus allowing a long integration period, with no need to recode all 
> processes familiar with the schema. The new schema will simply inherit the 
> old one, and only add information.
>  * Allow for full data control through polymorphism, and the ability to 
> replace structures within any supported language. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to