我们可以指定契约验证,可在编译时(静态)或在运行时(动态)执行校验。
Contract validation can be specified to be executed statically at build time or dynamically at runtime.
需要显式常量或是“魔力值”的很多API都是API契约的一部分,这些常量或数值并不只是随意添加到代码中的(这里的意思指的是很多API中都拥有一些常量或是数值,他们是API契约所要求的,因此根据反编译后的结果很难推测出这些常量或数值所代表的含义——译者注)。
Many APIs that expect explicit constants or 'magic values' are part of an API contract and not merely some value added in to the code.
编译器会根据契约来检查代码是否满足了所有的条件,并在出现状况时发出警告。
The compiler will make specific checks via Contracts to ensure that all the conditions specified are met, issuing warning if they are not.
应用推荐