President Barack Obama on Sunday urged college graduates to shun those who want to confront a rapidly changing world by building walls around the U.S. or by embracing ignorance, as he delivered a sharp and barely concealed critique of Donald Trump. Mr. Obama used his commencement speech at Rutgers University to illustrate a world view antithetical to the ideas espoused by the presumptive Republican presidential nominee. Looking out at a sea of red and black gowns, Mr. Obama told the roughly 12,000 graduating students that the pace of change on the planet is accelerating, not subsiding, and that recent history had proved that the toughest challenges cannot be solved in isolation. "A wall won't stop that," Mr. Obama said, bringing to mind Mr. Trump's call for building a border wall between the U.S. and Mexico. "The point is, to help ourselves, we've got to help others -- not pull up the drawbridge and try to keep the world out." The president never mentioned Mr. Trump by name, but his intended target seemed clear. Repeatedly, Mr. Obamareferred to disparaging comments about Muslims and immigrants, and opposition to free-trade deals. But he appeared most incensed by what he described as a rejection of facts, science and intellectualism that he said was pervading politics. "In politics and in life, ignorance is not a virtue," Mr. Obama said. "It's not cool to not know what you're talking about. That's not keeping it real or telling it like it is. That's not challenging political correctness. That's just not knowing what you're talking about," the president said. "And yet, we've become confused about this," he continued, warning that the rejection of facts and science would lead the U.S. on a path of decline. Mr. Obama's rebuke came as Mr. Trump is close to clinching the GOP nomination, raising the prospect that November's election could portend a reversal of Mr. Obama's policies and approach to governing. In recent days, Mr. Trump has started focusing on the general election while working to unite a fractured Republican Party around his candidacy. Democrats are readying for a fight against a reality TV host they never anticipated would make it this far. Mr. Obama has mostly steered clear of the election as Democrats Hillary Clinton and Bernie Sanders compete for the nomination. But he has used speeches such the Rutgers address to lay out themes that Democrats may ultimately use as they work to deny Mr. Trump the White House. New Jersey Gov. Chris Christie, who ran against Mr. Trump for the GOP nomination, has since endorsed him and become one of his most vocal surrogates. Mr. Christie didn't attend the president's speech at Rutgers, instead spending the day at Princeton University for his son's baseball game in the Ivy League championship. In his speech, Mr. Obama told graduates that when they hear people wax nostalgic about the "good old days" in America, they should "take it with a grain of salt." "Guess what? It ain't so," the president said, rattling off a list of measures by which life is better in the U.S. than in decades past. Some 50,000 students and their families packed High Point Solution Stadium for the ceremony, the first at Rutgers to involve a sitting president. The public university's leaders lobbied the president for years to come to campus for the school's 250th anniversary. Sunday's address was the second of three commencement speeches that Mr. Obama will deliver during his final graduation season as president. Earlier in May, Mr. Obama echoed similar themes about progress in the U.S. when he spoke at historically black Howard University in Washington. The president will also speak on June 2 at the U.S. Air Force Academy in Colorado Springs, Colo. Rutgers University also bestowed an honorary law degree on the president, adding to the half-dozen or so other honorary degrees that the Columbia and Harvard Law School graduate has received.