Call a Private Constructor

Calling a private constructor from outside its class can be done via Reflection as follows:

public final class Users {   private Users() {}  // static members}Class usersClass = Users.class;Constructor emptyUsersCnstr = usersClass.getDeclaredConstructor();emptyUsersCnstr.setAccessible(true);Users usersViaEmptyCnstr = emptyUsersCnstr.newInstance();
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: