dimanche 2 juillet 2023

How to fix a violation of the DRY principle?

    public Token match(ITokenType expectedToken, int tokenNum) {
        if(hasToken(_currentTokenNum))
            if(expectedToken == getToken(tokenNum).get_type())
                return getToken(tokenNum);
        return null;
    }

    public Token match(Class<?> clazz, int tokenNum) {
        if(hasToken(_currentTokenNum))
            if(clazz.isInstance(getToken(tokenNum).get_type()))
                return getToken(tokenNum);
        return null;
    }

I tried to make a single match method, and put the condition into two methods, but it didn’t work out.

Aucun commentaire:

Enregistrer un commentaire