(Reuters) - A federal judge on Tuesday declared unconstitutional a California law requiring IMDb, the movie and television information website, to remove actors’ ages at their request.

The Hollywood sign is seen in Hollywood, Los Angeles, California, U.S. October 19, 2017. REUTERS/Lucy Nicholson

U.S. District Judge Vince Chhabria said the law violated the First Amendment rights of IMDb, a unit of Amazon.com Inc that challenged the law, by singling out age data for special treatment, despite being intended to serve the compelling interest of curbing age discrimination in Hollywood.

“Regulation of speech must be a last resort,” the San Francisco-based judge wrote. “California has not shown that it adopted a measure ‘actually necessary’ to combating age discrimination.”

The law was passed in 2016. It drew support from SAG-AFTRA, a union representing some 160,000 actors, broadcast journalists and other media professionals, which plans to appeal.

“SAG-AFTRA is extremely disappointed with today’s ruling,” General Counsel Duncan Crabtree-Ireland said in a statement. “The court unfortunately fails to understand or recognize the massive impact gender and age discrimination has on all working performers.”

The office of California Attorney General Xavier Becerra, which defended the law, did not immediately respond to a request for comment.

IMDb did not respond to requests for comment.

While actors in Hollywood have long complained they are passed over for roles as they age, Chhabria said the California law’s advocates “seem to misunderstand” that the real problem might be gender discrimination.

He cited the willingness of many movie producers to team older actors with much younger female actresses in leading roles, and TV networks to pair older male anchors with younger female anchors, rather than hire men and women of similar ages.

“The defendants barely acknowledge this, much less explain how a law preventing one company from posting age-related information on one website could discourage the entertainment industry from continuing to objectify and devalue women,” he wrote. “If the government is going to attempt to restrict speech, it should at least develop a clearer understanding of the problem it’s trying to solve.”

Chhabria had last February issued a preliminary injunction against enforcement of the California law.

SAG-AFTRA combined the Screen Actors Guild and the American Federation of Television and Radio Artists.

Its president, Gabrielle Carteris, wrote in 2016 that she would never have won an audition for her role as 16-year-old Andrea Zuckerman in the 1990s hit TV show “Beverly Hills, 90210” had producers known she was 29 at the time.

The case is IMDb.com Inc v Becerra et al, U.S. District Court, Northern District of California, No. 16-06535.