I sometimes edit answers (usually to improve readability, add sources, etc..), but since there are several scenarios in which one might think an answer could be edited, I'm not sure what is the best approach in each one. Examples could be:
If the new answer is different because the old (and accepted one) is deprecated, edit and add the new code so users can understand that there are two ways to solve it (the old one and the new one).
If the new answer is different because the problem (question) itself can be caused by several factors and therefore have more than one solution, posting a new answer would be a better approach.
If you are now using a new language (such as Kotlin instead of java), but the solution is similar, adding a Kotlin version to the old answer could be a better approach.
Not saying that those examples are the way to go, but I'd like to understand what is the way to go in each scenario.