BERLIN — On the face of it, Germany appears to have little to gain from Brexit. Frankfurt might benefit as banks move their operations to the bloc, but the uncertain outlook is unsettling German exporters. Germany will miss the U.K.’s big budget contribution and its outward-looking approach.

But there’s one area in which the U.K.’s loss could be Germany’s gain: migration.

Germany is enjoying a growth spurt that has legs: The European Central Bank’s monetary policy remains accommodative and the next German government will have a €30 billion to €60 billion surplus to spend, adding further economic stimulus. But the biggest economy in Europe is also a ticking demographic time bomb: Germany’s median age is now 47, compared with 40 in the U.K. and 38 in the United States. And the number of Germans approaching retirement is growing strongly.

The inevitable result of buoyant businesses and retiring baby boomers will be a growing shortage of skilled workers. German industry is running at 86.7 percent of total capacity, according to EU business survey data, a high value by historical standards. But almost 20 percent of German firms also said that a shortage of labor is currently limiting their production — the highest value ever recorded.

Job openings, of which there are currently a record 780,000, have been difficult to fill in some professions, such as in engineering, software and health care. Unions are adding to the shortage. The metalworkers union IG Metall is demanding work time reductions instead of hefty wage increases. Employers, already struggling to fill jobs, have roundly rejected such demands, which may well lead to the first strike in the sector in 15 years.

There are two ways to tackle the shortage of workers: Companies can make better use of their existing employees — by offering more hours to part-time workers or retraining staff, for example — or they can try to attract migrants to fill the jobs.

In theory, moving to Germany has become easier for highly educated workers from outside the EU since the country loosened its immigration laws. What are deemed to be “worker shortage jobs,” as defined by Germany's state employment agency, are also open to migrants from outside the EU who have completed apprenticeship-type training.

But in practice, Germany has not been the magnet for skilled immigrants in the way Canada or the U.K. have.

Chancellor Angela Merkel's party has long struggled to accept the reality that Germany is a “country of immigration.” Some 18.5 million people in the country either were born without German citizenship, or have at least one parent who was born without German citizenship. German language, culture and bureaucracy also represent hurdles for many would-be immigrants. Unsurprisingly, Germany attracted just 40,000 “qualified” workers (those with a degree or apprenticeship) from outside the EU in 2016.

Migration to Germany from “older” EU member countries has traditionally been low. If the euro crisis drove some people northward, some may return now that these economies are recovering.

The largest potential influx is from Europe’s east. But even here, the numbers may not be high enough. Labor shortages in Central and Eastern European factories are even more severe than in Germany, according to EU survey data. The available pool of qualified migrants is likely to be smaller than many believe. Indeed, migration data from the eight Eastern states that joined in 2004 show that the numbers are already falling.

This is where Britain’s decision to leave the EU comes in. The U.K. became the most popular destination for migrants from the former Eastern Bloc after 2004. This was in large part thanks to its flexible and buoyant labor market, the English language, the attractions of London and the Labour government’s decision not to impose transitional controls on free movement.

During the eurozone crisis, the British economy also benefitted from a surge of young and well-educated European workers who were struggling to find jobs in Spain, Italy, Ireland and elsewhere.

But after last year’s Brexit referendum, net migration of EU citizens to Britain fell sharply amid hostility to free movement and to migrants themselves. Consumed by political chaos, the U.K. government failed to reassure EU citizens that their rights would be protected. The depreciation of the pound also made the U.K. a less attractive place to work.

The biggest drop — almost to zero — in migrant arrivals came from Eastern member countries that had joined the bloc in 2004. In contrast, Germany has become the primary destination for migrants from Eastern Europe, with net immigration totaling almost 1 million between 2011 and 2015.

With its comparatively old population, retiring baby boomers, growing economy and reasonably flexible labor market and immigration conditions, Germany has the most to gain as Brexit changes patterns of migration within the EU.

Having been denied the chance to have their say in the Brexit referendum, many young skilled EU workers who are in the U.K. (and those that might have considered going to Britain) may now choose to vote with their feet. As Germany tries to head off its own winds of instability, it would do well to welcome them with open arms.

Christian Odendahl is chief economist and Berlin representative at the Centre for European Reform.