After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 694895 - Support for covariance and contravariance of generics and restrictions on them
Support for covariance and contravariance of generics and restrictions on them
Status: RESOLVED DUPLICATE of bug 668474
Product: vala
Classification: Core
Component: Generics
unspecified
Other All
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2013-02-28 19:19 UTC by Maciej (Matthew) Piechotka
Modified: 2016-11-30 15:31 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Maciej (Matthew) Piechotka 2013-02-28 19:19:54 UTC
1. It would be nice to introduce a covariance/contravariance in types:

    public void insert<T>(T item, List<? super T> list) {
        list.add(item); // Ok. If list have type List<G> then T is subtype of G
    }

    public void T get_random<T>(List<? extends T> list) {
        int elem = rand.rand_int (0, list.size);
        return list.get(elem); // Ok. If list have type List<G> then G is subtype of T
    }

2. It would be nice to allow restriction on arguments:

public abstract MyCollection<C extends Collection<int>> {
    public MyCollection(C c) {
        c.add(0); // Ok. C is Collection<int> so we can call add
    }
    public C col;
}

List<int> l = new ArrayList<int>();
MyCollection<List<int>> c = new MyCollection<List<int>>(l);
List<int> l2 = c.col; // Ok. c.col have type List<int>
Comment 1 Al Thomas 2016-11-30 15:31:06 UTC

*** This bug has been marked as a duplicate of bug 668474 ***