Why does @FunctionalInterface have a RUNTIME retention?

前端 未结 3 1341
误落风尘
误落风尘 2020-12-11 15:43

Said in Javadoc:

If a type is annotated with this annotation type, compilers are required to generate an error message unless ...

3条回答
  •  星月不相逢
    2020-12-11 16:13

    "Source" would not be enough, since if for example you create an API and provide your class as a pre-compiled jar, the information would not be available for the compiler anymore.

    I believe "class" would also not be enough if you want to support those kind of compilers that "compile" against a class at runtime, like scripting engines that use reflection to find out about those annotations and should show a warning, too.

提交回复
热议问题