Can a program depend on a library during compilation but not runtime?

前端 未结 10 1800
深忆病人
深忆病人 2020-11-30 18:18

I understand the difference between runtime and compile-time and how to differentiate between the two, but I just don\'t see the need to make a distinction between compile-t

10条回答
  •  星月不相逢
    2020-11-30 18:36

    To answer the question "how can a program not depend on something at runtime that it depended on during compilation?", let's look at the example of an annotation processor.

    Suppose you've written your own annotation processor, and suppose it has a compile-time dependency oncom.google.auto.service:auto-service so that it can use @AutoService. This dependency is only required to compile the annotation processor, but it is not required at runtime: all other projects depending on your annotation processor for processing annotations do not require the dependency on com.google.auto.service:auto-service at runtime (nor at compile-time nor at any other time).

    This is not very common, but it happens.

提交回复
热议问题