Barack Obama has said that the world "can't hide behind a wall" to shield themselves from the turmoil and poverty of other nations during a trip to Germany

The pointed reference to Donald Trump, came as both the current and former presidents find themselves in Europe, in a scheduling accident which invites direct comparison between their two radically different tenures.

He didn’t mention his successor’s name once, but made an apparent reference to Mr Trump’s vow to build a wall on the southern US border with Mexico that has come to symbolise the sitting president’s penchant for isolationist rhetoric.

“If there are disruptions in these countries, if there is bad governance, if there is war or if there is poverty, in this new world that we live in we can't isolate ourselves,” he said. “We can’t hide behind a wall.”

The Obama Foundation says the former President accepted the invitation before the US election, so the overlap with Mr Trump's first presidential trip to Europe is purely coincidental.

Speaking in front of the Brandenburg Gate alongside German Chancellor Angela Merkel, Mr Obama pushed his vision of continued openness between nations, saying that globalisation and technology were shrinking the world.

Answering a question on the refugee crisis, he said: “In the eyes of God, a child on the other side of the border is just as worthy of compassion and love as my own child. We can’t distinguish between them in terms of their worth.

“But we are heads of nation states, and we have finite resources. Part of the job of governments is to express solidarity while operating within legal and national constraints.”

President Trump and President Macron have awkwardly long handshake

“The world is at a crossroads,” Mr Obama added. The widening inequality gap inside nations as well as between nations was a major concern, he said. At the same time, “The world has never been wealthier, more healthy and never been better educated.”

“If we can sustain that progress, then I'm very optimistic about our future. My job now is to help them take it to the next step,” Mr Obama said.

In another speech later in the southwestern German town of Baden-Baden where he accepted a German media prize, Obama said he was concerned about how technology advances had made “it ironically easier for people to retreat into our own bubbles.”

He added: “We can find people on the internet who agree with our ideas, no matter how crazy. Democracies do not work if we are not operating on some level based on reason and fact and logic - and not just passion. We're going to have to find ways to push back on propaganda and listen to those we don't agree with.”

Ms Merkel met both Mr Obama and Mr Trump, travelling from Berlin to Brussels for a Nato meeting.

While Mr Obama was met with cheering crowds at the Kirchentag, a traditional four-day Protestant festival, President Trump arrived in Brussels as tens of thousands of protesters attended “Trump Not Welcome” demonstration.

The President ifaced a difficult meeting at the Nato summit. Although he has recently changed his mind about the usefulness of the 28-nation bloc, declaring that it was “no longer obsolete”, he faced tough questions on a number of issues, including climate change and Russia.

As for what happens once a president leaves the White House. Mr Obama said he had spent the last four months “trying to catch up with my sleep” and spending more time with his family.

“I'm very proud of the work I did as president,” he said, adding he was especially proud of health care reform.

“My hope was to get 100 percent of people health care. We didn't quite achieve that but we were able to get 20 million people health care who didn't have it before. Certainly I have some regrets that we weren't able to get everyone health care.

“Now some of the progress we made is imperiled because a significant debate is taking place in the United States,” he added, again avoiding direct mention of Mr Trump, who is attempting to dismantle the so-called Obamacare.

Just four months before Germany's election, Mr Obama's mere appearance with Ms Merkel, broadcast live on four networks, raised concerns that he was helping her re-election campaign.

But Mr Merkel and Mr Obama stayed away from the campaign with their discussion focused on faith and politics in general.

He said he hopes to use the “little influence” he has as a former president to help young people be better prepared for the looming challenges.