int[] iv = [1, 2, 3];

// Assigning `int[]` to `any[]` is allowed.
// - set of values allowed by `int` is subset of set of values allowed by `any`
// - set of values allowed by `int[]` is subset of set of values allowed by `any[]`
any[] av = iv;

public function main() {
    // Runtime error; otherwise `iv[0]` would have wrong type.
    av[0] = "str";
}

Covariance

Arrays and maps are covariant. Static type-checking guarantees that the result of a read from a mutable structure will be consistent with the static type. Covariance means that a write to a mutable structure may result in a runtime error. Arrays, maps, and records have an “inherent” type that constrains mutation.

int[] iv = [1, 2, 3];
any[] av = iv;

Assigning int[] to any[] is allowed. - set of values allowed by int is subset of set of values allowed by any - set of values allowed by int[] is subset of set of values allowed by any[]

public function main() {
    av[0] = "str";
}

Runtime error; otherwise iv[0] would have wrong type.

bal run covariance.bal
error: {ballerina/lang.array}InherentTypeViolation {"message":"incompatible types: expected 'int', found 'string'"}
        at covariance:main(covariance.bal:10)