It's a little ironic to hear talk like this, since around here I hear a lot of "sorry your coal mining job is going away, but you need to get with the times and train for something relevant". Same thing applies here. If you pick a programming specialization that eventually falls out of favor, buck up and learn a new one. Maybe that'll mean a pay cut for a bit as you ramp up, but that's just how it works.
It's a different story, I guess, if you go into a completely different type of programming from what you're used to (say Web apps to embedded programming), but I don't think that's necessarily easy.
Important difference.
For example, at one extreme, all tech lasts exactly three years; at one of several other extremes, 50% of tech is eternal and the rest lasts exactly 1.5 years.