NEW YORK (Reuters) - Former President Barack Obama used a rare public appearance on Wednesday to question Republicans’ latest effort to repeal his signature healthcare law, saying it would inflict “real human suffering” on Americans.

Slideshow ( 5 images )

In his speech at a Bill and Melinda Gates Foundation event in New York City, Obama also laid out an optimistic vision of the world’s future while implicitly criticizing Republican President Donald Trump’s “America First” philosophy.

The remarks were one of the few times that Obama, a Democrat, has spoken publicly since he left office in January.

“It is aggravating,” Obama said of the Republican attempt to eliminate Obamacare. “It’s certainly frustrating to have to mobilize every couple of months to keep our leaders from inflicting real human suffering on our constituents.”

But Obama said the healthcare fight was a good example of the way that advancement is often made: through fits and starts, with backward steps tempering every success.

“Progress is never inevitable,” he said. “It can often be fragile; it’s in need of constant renewal.”

The true test, he said, was in how people respond in times of difficulty, when their efforts to make the world better run into resistance.

“Your response has to be to reject cynicism and reject pessimism and to push forward with a certain infectious and relentless optimism,” he said. “Not blind optimism, not one that ignores the scale and the scope of challenges, but that hard-earned optimism that is rooted in the stories of very real progress that have occurred throughout human history.”

The speech came a day after Trump addressed the United Nations General Assembly for the first time as president, offering a full-throated defense of nationalism and expressing skepticism about multilateral foreign policy.

During a question-and-answer session with Bill and Melinda Gates after his speech, Obama said the United States cannot hope to solve the world’s biggest problems, such as climate change or mass migration, on its own.

As he has largely done since leaving office, Obama did not mention Trump by name, but he made it clear that he disagreed with the president’s viewpoint.

“You don’t have to cede your sovereignty or it doesn’t make you less patriotic to believe that,” Obama said. “You just have to have some sense - and read.”