Improve generics handling

Fixes #750
I would combine both of those if clauses to `if (Objects.equal(getVarName(param), varName))`

there are already type checks and casts in that method