The birth rates are falling fast in all the world’s more prosperous countries, but the generation now in their middle years have not yet grasped what that means for their later years. If they end up needing some sort of assisted living, either at home or in a care home, they will probably be looked after by a robot.

Not to worry: Robots can already pick soft fruit, so in another 30 or 40 years they’ll probably be able to wipe your bottom. (We’re all going to live a very long time, except for those who don’t.) We’ll need the robots because there won’t be enough real people of working age to look after the elderly.

The Chinese, whose population has already stopped growing and is predicted to drop by half by the end of the century, have a phrase that sums it up: the “4:2:1” home. It’s a household where there are four grandparents, cared for by two working-age parents, who themselves have only one child.

It’s a strain on the middle generation even when the child is small and the grandparents have only recently retired. When the grandparents are very old and frail, and the middle generation has already stopped working (retirement age in China is 60 for men, 55 for women), the whole weight of care falls on the shoulders of just one young man or woman.

It’s called the dependency rate, and it’s going up fast. In 1975, there were 7.7 people in the Chinese workforce for every person over 60; by 2050, the ratio will be only 1.6 employed persons for every retiree. And although China gets most of the attention, there are two dozen other countries that also face a drop of half in their populations by 2100.

It will happen to Spain and Italy, to Brazil and Japan, to Korea and Thailand. It won’t quite happen to India, whose population will probably peak around 1.6 billion in the mid-2040s before collapsing back down to slightly below a billion in 2100, but the yoyo-ing up and down will be enough to give the country motion sickness.

So when the Chinese census results were released last week, there was a torrent of commentary about how the rich countries (including China) will have to open their borders wide to immigrants from the countries where the population is still growing, mostly in Africa and the Middle East.

Otherwise, the pundits calculated, there won’t be enough people in the rich countries to work in the factories, run the infrastructure, and care for the old. It sounds like a perfect fit — but it is almost certainly wrong.

The populations of Middle Eastern and African countries are indeed still growing, and quite fast. In fact, that’s where almost all the remaining growth in the world’s population will happen, from 7.8 billion now to a peak of 9.7 billion in 2064, and then back down to 8.8 billion by the end of the century (according to the most recent forecast, published in The Lancet last year).

What these figures embody but conceal, however, is that the growth in the poor countries continues until 2100, doubling, tripling or even quadrupling the population in countries like Egypt, Nigeria and Tanzania — which means that they probably stay poor. The overall decline in world population later in the century is driven solely by the collapse of population in the rich countries.

So there will still be lots of hungry people in the poor countries eager to move to the rich ones, and a growing shortage of labor in the rich ones — but the poor will still probably not be allowed in. Identity politics trumps economics almost every time.

Almost any country, even with no previous experience of immigration, can cope with an influx of 10 percent foreigners in a generation. They will tend to be younger and have more babies, so their descendants may wind up as 20 percent or 25 percent of the population — but by then they will be culturally “local.” The basic culture stays recognizable, though subtly changed and even enriched.

But almost no country, however tolerant, will accept an influx of 25 percent or 30 percent foreigners in a generation, especially when differential birth rates mean that 30 or 40 years on, they will be more than half the population. That’s how many “New Danes” and “New Chinese” would be needed to solve the problem by immigration, so it isn’t going to happen.

The problem will be solved instead by an ever wider use of automation and robots. Immigrant labor may be more cost-effective than machines, and sometimes kinder as well, but the machines don’t have the same problematic cultural baggage.

Not until the AI goes “Skynet,” at least. But that’s probably still quite a long way off.

Gwynne Dyer is an independent journalist, based in London.