If you put two metals together in water, one of them corrodes to protect the other. This is known as electrolysis. The action of a sacrificial anode rod, and that of a battery, are both examples of beneficial electrolysis. However, usually in plumbing, electrolysis is something you want to avoid, especially in connections, since it means that the corroding part is eventually going to leak.
To prevent plumbing electrolysis, dielectric connections are used to separate dissimilar metals. These photos show three ways to do that. The photo on the left shows a 3/4-inch copper flex line. These are fairly common on residential water heaters.
The photo at right actually is rather unusual. On commercial water heaters, one often finds dielectric unions (the lefthand connection); once in awhile, one finds stainless steel flex lines (the righthand connection). It’s quite rare, however, to find a water heater that has one of each!