简体   繁体   中英

Intellij showing nonstandard annotations on standard Java classes?

Whilst using Intellij Idea quick documentation feature ( CTRL + Q ) sometimes I find standard JDK classes to be annotated by nonstandard annotations. Those annotations are not there when one CTRL -clicks the annotated feature to view its source code. For example, the following picture shows argument of java.util.Collections.unmodifiableList to be annotated with @org.jetbrains.annotations.NotNull :

用于 java.util.Collections.unmodifiableList 的 QuickDoc

Why would a standard class be decorated with third party annotation?

This is not consistent, as for example, checkedNavigableSet from java.util.collections is annotated differently, no package for @NotNull is given:

CheckedNavigableSet 的 QuickDoc

The phenomenon does not preclude development, I am just curious as to the cause of QuickDoc behaving that way. Maybe those annotations put there by Intellij team for convenience?

According to doc from here that annotations are used by Idea's inspection mechanism, so statement Collections.unmodifiableList(null) is marked with warning of non-null contract violation. As you noticed this annotations are not being present in original code, so I guess they were added somewhere in a middle between JDK and Editor. It's still unclear why it appears with package or without it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM