Vavr: Type safety

Created on 3 Apr 2018  路  3Comments  路  Source: vavr-io/vavr

Hello,

I see there are various implementations of Seq interface, but at runtime I get class class exception when retrieving the values in such a structure.
It seems like type inference cannot tell what is inside that structure?
Sometimes it is an Array and othertimes is a List<List<Array<...
I cannot use the Iterator to traverse it, as there is no awareness of the elements inside it at runtime.

E.g:
I have written some validators which all return Seq<String> for the errors data structure, and I expected it to be independent of the runtime implementation when calling methods on the interface: like iterator method: reduceLeft.

Seq<String> errorsIterator = exception.getValidationResult().getError();
String errors = errorsIterator.iterator().reduceLeft((s, s2) -> s +" " + s2);

java.lang.ClassCastException: io.vavr.collection.Array cannot be cast to java.lang.String

Why isn't this error shown at compile time? It forces the client to call instanceOf on elements and take decisions from there.

Thank you,

Livia

question

Most helpful comment

@liviamoroianu I hope you don't mind if I close this issue because of house-keeping. I think the issue is located on the call-site, not within Vavr.

Nevertheless, if you could give us a MWE (see above) I will re-open the issue and fix it.

All 3 comments

I don't meet the ClassCastException before.

Can you show reproducible code example with ClassCastException?

@liviamoroianu could you please provide us with a minimal working example? E.g. by hard coding/substituting a minimal version of exception.getValidationResult().getError() that leads to the error you described.

@liviamoroianu I hope you don't mind if I close this issue because of house-keeping. I think the issue is located on the call-site, not within Vavr.

Nevertheless, if you could give us a MWE (see above) I will re-open the issue and fix it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

roookeee picture roookeee  路  5Comments

bhchandra picture bhchandra  路  3Comments

paplorinc picture paplorinc  路  6Comments

manu-m picture manu-m  路  6Comments

yarulan picture yarulan  路  5Comments