beamer overprint with itemize

So, the following question was sent to the beamer mailing list, and after spending over an hour trying to answer what I thought would be a trivial question, I figured I might as well put the answer here. (I'm going to feel very silly if this turns out to be a duplicate.) The idea is that you start with something like this:

\documentclass{beamer}
\let\Tiny\tiny
\begin{document}
\frame{
\begin{itemize}
\only<1> {
\item Foo
\item Bar
}
\only<2> {
\item I replace Foo
\item I replace Bar
\item I am new!
}
\end{itemize}
}
\end{document}


Now, since they are of different sizes, this makes the itemize jump around on the slide. We need some grouping of the items that reserves space for the contents of the largest group.

• What if "I replace Foo" takes up two lines? Feb 9 at 11:53
• I don't understand the question. If it takes up two lines then it... takes up 2 lines
– Mark
Feb 9 at 17:38
• I mean, if in <1> it was Foo\\second line, and in <2> still only one line, does the solution still work? Feb 13 at 10:13
• I believe both posted solutions still work. Try and see!
– Mark
Feb 14 at 17:07

It is definitely possible to use only one itemize environment in this case. You could simply replace Foo and Bar using the \alt command. In my opinion the resulting code is also easier to read. Here is an example:

\documentclass{beamer}
\begin{document}
\frame{
\begin{itemize}
\item\alt<1>{Foo}{I replace Foo}
\item\alt<1>{Bar}{I replace Bar}
\item<2> I am new!
\end{itemize}
}
\end{document}


OUTPUT:

• You are right, this is way better!
– Mark
Apr 20, 2016 at 18:20

It turns out that this works:

\documentclass{beamer}
\let\Tiny\tiny
\begin{document}
\frame{
\begin{overprint}
\onslide<1>
\begin{itemize}
\item Foo
\item Bar
\end{itemize}
\onslide<2>
\begin{itemize}
\item I replace Foo
\item I replace Bar
\item I am new!
\end{itemize}
\end{overprint}
}
\end{document}


This looks pretty simple (to me). What's surprising is the other simple looking solutions that fail. (For instance, just try doing this using a single itemize environment.)