public Type getCompatibleType ( Type other ) { if ( other == null ) { return null ; } if ( equals ( other ) ) { if ( this == NULL_TYPE ) { return other ; } else { return this ; } } Class < ? > classA = mObjectClass ; Class < ? > classB = other . mObjectClass ; Type compat ; if ( classA == Void . class ) { if ( classB == Void . class ) { compat = this ; } else { return null ; } } else if ( classB == Void . class ) { return null ; } else if ( other == NULL_TYPE ) { compat = this . toNullable ( ) ; } else if ( this == NULL_TYPE ) { compat = other . toNullable ( ) ; } else if ( Number . class . isAssignableFrom ( classA ) && Number . class . isAssignableFrom ( classB ) ) { Class < ? > clazz = compatibleNumber ( classA , classB ) ; if ( isPrimitive ( ) && other . isPrimitive ( ) ) { compat = new Type ( clazz , convertToPrimitive ( clazz ) ) ; } else { compat = new Type ( clazz ) ; } } else { // TODO: ensure generics are matched // ie: List<Number> and List<Integer> = List<Number> compat = new Type ( findCommonBaseClass ( classA , classB ) ) ; } if ( isNonNull ( ) && other . isNonNull ( ) ) { compat = compat . toNonNull ( ) ; } return compat ; }
Returns a type that is compatible with this type and the one passed in . The type returned is selected using a best - fit algorithm .