reflectively calling static private member variables of a class
public static void clearApiService() { try { Field field = APIServiceFactory.class.getDeclaredField("mServiceInstanceMap"); field.setAccessible(true); Object obj = field.get(APIServiceFactory.class); Method clearMethod = Map.class.getDeclaredMethod("clear"); clearMethod.invoke(obj); } catch (NoSuchFieldException e) { e.printStackTrace (); } catch (IllegalAccessException e) { e.printStackTrace (); } catch (NoSuchMethodException e) { e.printStackTrace (); } catch (InvocationTargetException e) { e.printStackTrace (); } }