4. Given the complex number $z=x+y \mathrm{i}(x, y \in \mathbf{R})$, and $z^{2}=8 \mathrm{i}$. Then $z=(\quad$.
(A) $2+2$ i
(B) $-2+2 \mathrm{i}$ or $2-2 \mathrm{i}$
(C) $-2-2$ i
(D) $2+2 \mathrm{i}$ or $-2-2 \mathrm{i}$
4. D.

From the given, $x^{2}+2 x y \mathrm{i}-y^{2}=8 \mathrm{i} \Rightarrow x=y= \pm 2$.