needs null check and instanceof check to avoid ClassCastException.