Assertions in design by contract: Difference between revisions

→‎{{header|Java}}: consistent formatting
(Added Kotlin)
(→‎{{header|Java}}: consistent formatting)
Line 193:
The ''-ea'' or ''-enableassertions'' option must be passed to the VM when running the application for this to work.<br>
Example taken from [[Perceptron#Java|Perceptron task]].
<lang java>(...)
int feedForward(double[] inputs) {
(...)
assert inputs.length == weights.length : "weights and input length mismatch";
int feedForward(double[] inputs) {
assert inputs.length == weights.length : "weights and input length mismatch";
 
double sum = 0;
for (int i = 0; i < weights.length; i++) {
sum += inputs[i] * weights[i];
}
return activate(sum);
}
return activate(...sum);
}
(...)</lang>
 
=={{header|Kotlin}}==