报告扩展、实现或重写使用 @ApiStatus.NonExtendable 标记的 API 元素的类、接口和方法。

@ApiStatus.NonExtendable 注解表示不得扩展、实现或重写类、接口或方法。 将此类接口和类转换为内部库实现很常见,因此,如果客户端提供不同的实现,将获得 ClassCastException。 将新的 abstract 方法添加到这种类和接口将破坏与客户端实现的兼容性。

示例:


  // In upstream library code
  @ApiStatus.NonExtendable
  public interface MyService {
    public void perform();
  }

  // In downstream client code
  public class MyServiceImpl implements MyService {
    @Override
    public void perform() {
      // ...
    }
  }
This inspection also detects the following problems related to applying the annotation incorrectly: