Some people make their answers Community Wiki and leave a note saying "here is what you shouldn't do", so that they don't continue to lose reputation from downvotes for a wrong answer.
If it's wrong, it will very likely get downvoted, and after a few downvotes it will become dimmed and appear last, exactly as you suggest. If it's CW, then you don't lose any rep for this.
Although speaking personally, I don't feel that it's a really appropriate use of the wiki system, I'm just mentioning what some people do. I'd just delete the answer, because ultimately a wrong answer is simply noise. I do understand the perspective of wanting other people to learn from your mistakes, but most people simply won't get that far, they'll look at the accepted answer or top 2-3 answers and then move on.
Worse, if your answer has upvotes, leaving it up can be actively harmful; some people may not realize that it's been left up "for posterity" and actually attempt what you've suggested. Especially when it comes to code snippets, people have a remarkable ability to ignore anything and everything around the code while they copy and paste.
I know it's hard to delete an upvoted answer, but most of the time you'll be doing the readers a favour.