[MDSAL-513] Consider using covariance in generated interfaces' collections Created: 23/Jan/20  Updated: 23/Jan/20

Status: Confirmed
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Low
Reporter: Robert Varga Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We currently generate interfaces which result in:

List<Foo> getFoo();

i.e. we are using invariant type for the returned List. This is kind of okay and is readable by novices, but has a downside - there are no compile-time guards against attempted mutation of the collection - which usually will end up blowing up at runtime.

We should consider returning covariants, such that the above becomes:

List<? extends Foo> getFoo();

This has the benefit of allowing reads from the List, but writes are stopped cold by the compiler - you just cannot put anything into the list (unless you battle the type system and perform a raw/unchecked cast).


Generated at Wed Feb 07 20:09:59 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.