Is Collection(T) covariant on T? [message #1744472] |
Tue, 27 September 2016 10:51 |
Denis Nikiforov Messages: 346 Registered: August 2013 |
Senior Member |
|
|
Hi!
According to the Section 11.7.5 of the OCL Specification 2.4 Sequence type has the following operation:
including(object : T) : Sequence(T)
I expect that the following expression will return invalid value.
Sequence{1, 2, 3}->including('string')
Because operation including(String) is not defined for Sequence(Integer). I expect that type T of the argument must conform to the type T of the source Sequence(T). Also the resulting and source collections will have the same Sequence(T) type.
But the result of the expression is the Sequence{1,2,3,'string'} with a Sequence(OclAny) type.
Even the following expression has the same result:
let coll : Sequence(Integer) = Sequence{1,2,3} in coll->including('string')
Is it true that OCL Sequence(T) is covariant on T? Integer is a subtype of OclAny. So Sequence(Integer) is a subtype of Sequence(OclAny). And so the operation including(OclAny) is defined for Sequence(Integer)?
[Updated on: Tue, 27 September 2016 10:52] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04269 seconds