Inspectopedia Help

Confusing 'main()' method

Reports methods that are named "main", but do not have the public static void main(String[]) signature in Java up to 21. Starting from Java 21 Preview, inspection doesn't highlight in case of package-private, protected or instance main methods, also without parameters. Additionally main methods located in anonymous or local classes are reported. Anonymous and local classes do not have a fully qualified name and thus can't be run.

Such methods may be confusing, as methods named "main" are expected to be application entry points.

Example:

class Main { void main(String[] args) {} // warning here because there are no "public static" modifiers }

A quick-fix that renames such methods is available only in the editor.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

ConfusingMainMethod
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Probable bugs

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024