0

I've been using Android Studio (that is based on IntelliJ IDEA), and fine with using annotations such as @NonNull.

In addition to Android Studio, I installed IntelliJ IDEA. I found that annotations such as @NonNull are not working. When I build the project, I got the error message:

java: cannot find symbol
  symbol:   class NonNull
  location: class Main

Could you show me how to enable the standard annotations in IntellJ IDEA?

[Edit 1]:

In IntelliJ IDEA: Settings -> Build, Execution, Deployment -> Compiler -> Configure annotations -> org.jetbrains.annotations.NotNull already checked.

[Edit 2]:

In Eclipse: I have no problems using the @NonNull annotation. I ran into the same problem of unresolved annotation symbol in Eclipse at the beginning, however, the quick fix tips popped up on Eclipse (when I pointed the cursor to the unresolved symbol) helped me fix the problem.

By clicking the quick fixes:

  • Eclipse added "org.eclipse.jdt.annotation_2_2.600.v2020408-1511.jar" under Referenced Libraries.
  • Also, Eclipse added "requires org.eclipse.jdt.annotation;" in module-info.java.

At the time of writing, I haven't been able to get @NonNull working in IntelliJ.

autumnmaple
  • 201
  • 2
  • 9

1 Answers1

0

I solved the problem. My issue was about using regular Java annotations in IntelliJ IDEA. Here is the solution.

  • Project Structure -> Libraries -> the 'plus' button -> From Maven -> org.jetbrains:annotations:16.0.2 -> OK
  • In the Java code, use @NotNull (instead of @NonNull)
  • In the Java code, import org.jetbrains.annotations.NotNull;

Besides, I was asked which JDK version that I used. I've been experimenting some latest Java features by using JDK 14.0.2.

Here is my code example:

Function<String, Boolean> checkFavoriteDrink = (@NotNull var drink) -> {
    return switch (drink) {
        case "mocha", "cappuccino", "iced tea" -> true;
        default -> false;
    };
};
autumnmaple
  • 201
  • 2
  • 9