refactor to use Array.newInstance()