Github user tillrohrmann commented on the pull request:

    https://github.com/apache/flink/pull/1104#issuecomment-138519198
  
    +1 for `hashCode()`, `equals()` and `toString()` abstract. But also for 
introducing `canEqual` as proposed by Martin Odersky 
(https://www.artima.com/lejava/articles/equality.html). The reason is that we 
currently have the odd behaviour that the `equals` method of `TypleTypeInfo` 
and `TupleTypeInfoBase` is not an equality relation (reflexive, symmetric, 
transitive, consistent). The following code demonstrates this:
    
    ```
    TupleTypeInfo<Tuple1<Integer>> tupleTypeInfo = new 
TupleTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO);
    
    TupleTypeInfoBase<Tuple1> anonymousTupleTypeInfo = new 
TupleTypeInfoBase<Tuple1>((Class<Tuple1>)Tuple1.class, 
(TypeInformation<?>)BasicTypeInfo.INT_TYPE_INFO) {
    
        @Override
        public TypeSerializer<Tuple1> createSerializer(ExecutionConfig config) {
                return null;
        }
    
        @Override
        protected void initializeNewComparator(int localKeyCount) {}
    
        @Override
        protected void addCompareField(int fieldId, TypeComparator<?> 
comparator) {}
    
        @Override
        protected TypeComparator<Tuple1> getNewComparator(ExecutionConfig 
config) {
                return null;
        }
    
        @Override
        public String[] getFieldNames() {
                return new String[0];
        }
    
        @Override
        public int getFieldIndex(String fieldName) {
                return 0;
        }
    };
    
    System.out.println(tupleTypeInfo.equals(anonymousTupleTypeInfo)); // false
    System.out.println(anonymousTupleTypeInfo.equals(tupleTypeInfo)); // true
    ```
    
    Thus, the symmetric condition is violated.
    
    This should actually be the norm for all future equality implementation, 
IMHO.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to