有时我们需要修改实例私有变量的值,例如通过下面的方法,可以将pushedNotification 实例中的私有变量transmissionCompleted的值设为true

PushedNotification pushedNotification = new PushedNotification(device, null, null);

  Field transmissionCompleted = PushedNotification.class.getDeclaredField("transmissionCompleted");
  transmissionCompleted.setAccessible(true);
  transmissionCompleted.setBoolean(pushedNotification, true);