Cast class to avoid reflection