public < T extends Type > T selectCandidate ( T candidate , T next , T actual , Environment environment ) { // Found a viable candidate boolean left = subtypeOperator . isSubtype ( candidate , next , environment ) ; boolean right = subtypeOperator . isSubtype ( next , candidate , environment ) ; if ( left && ! right ) { // Yes, is better than current candidate return next ; } else if ( right && ! left ) { return candidate ; } // Unable to distinguish options based on subtyping alone left = isDerivation ( next , actual ) ; right = isDerivation ( candidate , actual ) ; if ( left && ! right ) { // Yes, is better than current candidate return next ; } else if ( right && ! left ) { return candidate ; } else { return null ; } }
Given two candidates return the more precise one . If no viable candidate return null ;