How to disable “Access can be package-private” message in IntelliJ?

前端 未结 5 489
梦如初夏
梦如初夏 2021-01-31 13:20

Developing an API, the warning message \"Access can be package-package\" in Java classes can be really annoying.

I\'ve already spent some time going through the setting

相关标签:
5条回答
  • 2021-01-31 13:39

    Move the cursor to public , press Alt + Enter and choose one of the options:

    0 讨论(0)
  • 2021-01-31 13:42

    Another solution not mentioned so far: if you have a method that's declared public, and the IDE is telling you that there are no references to the method from outside the package, then perhaps you need to add a test case that calls that method from outside the package. In other words, treat the warning as signalling the absence of a test case for a public method.

    0 讨论(0)
  • 2021-01-31 13:48

    The inspection rule is "Declaration access can be weaker" and there are two options which can be disabled "Suggest package-private visibility level..."

    0 讨论(0)
  • 2021-01-31 13:51

    Go to Settings → Editor → Inspections then Java → Declaration redundancy → Declaration access can be weaker rule.
    Here you can either disable it at all or select the suggestion options on the right pane:

    0 讨论(0)
  • 2021-01-31 13:55

    To disable on a case by case basis, use

    @SuppressWarnings("WeakerAccess")
    
    0 讨论(0)
提交回复
热议问题