添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I’m asking it with no offense, just for a curiosity.

While I was coding my own org.springframework.web.method.support.HandlerMethodArgumentResolver implementation, I met a new requirement for myself, which is “Can I tell this ‘target’ parameter is Kotlin nullable ?”. At a first glance, I knew that there’s org.springframework.core.MethodParameter#hasParameterAnnotation so I thought that this problem is easily solved, but what an unlucky day!

Ditched in about half hours with debugger, I finally figured out that it is impossible, because while Kotlin nullable is compiled into jvm environment, it is annotated with @org.jetbrains.annotations.Nullable but it is marked as RetentionPolicy.CLASS , on contrast to @javax.annotation.Nullable is declared as RetentionPolicy.RUNTIME .

I know that there’s a method isMarkedNullable in KType but in this scenario I only could get java.lang.Class not KClass , and during the conversion between KClass and KType , such “marked as nullable” information is completely gone because those two types are incompatible( discussed in here already ).

Fortunately I found another workaround which is totally off from this topic, but still my curiosity is not resolved. Could anybody tell me some background story, reasons for this decision, etc., please?