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

前端 未结 10 1768
深忆病人
深忆病人 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:41

    Generally you are right and probasbly it is the ideal situation if runtime and compile time dependencies are identical.

    I will give you 2 example when this rule is incorrect.

    If class A depends on class B that depends on class C that depends on class D where A is your class and B, C and D are classes from different third party libraries you need only B and C at compile time and you need also D at runtime. Often programs use dynamic class loading. In this case you do not need classes dynamically loaded by library you are using at compile time. Moreover often the library chooses which implementation to use at runtime. For example SLF4J or Commons Logging can change the target log implementation at runtime. You need only SSL4J itself at compile time.

    Opposite example when you need more dependencies at compile time than at runtime. Think that you are developing application that has to work at different environments or operating systems. You need all platform specific libraries at compile time and only libraries needed for current environment at runtime.

    I hope my explanations help.

提交回复
热议问题