Example 4 Given that $a, b$ are real numbers, the set $A=\left\{a, a^{2}, a b\right\}, B=\{1, a, b\}$, if $A=B$, find the value of $a^{2004}+b^{2004}$.
Solution: Since $a=A \cap B$, and $A=B$, we get: $\left\{\begin{array}{l}a^{2} \cdot a b=1 \cdot b \\ a^{2}+a b=1+b\end{array}\right.$, so $\left\{\begin{array}{l}b\left(a^{3}-1\right)=0 \\ (a-1)(1+b)=0\end{array}\right.$, by the distinctness of elements in a set, we get $a \neq 0,1$. Therefore, $a=-1, b=0$.
Comment: This problem skillfully applies the properties of sets, avoiding the need for case analysis.