Inhert from the superclass's placeholder

T conforms Collection and AnyObject. I want to know if I subclass Base if I can make the subclass's placeHolder inherit the superclass's placeholder?


class Base<T: Collection & AnyObject> {
    var val: T
    init(val: T) {
        self.val = val

T is the superclass's placeholder, T.

class Sub<U: T & Comparable>: Base<U> {

How can I do something like this?

There’s not an automatic way to do this today; you’ll just have to redeclare the Collection and AnyObject constraints on U alongside Comparable.

1 Like
Terms of Service

Privacy Policy

Cookie Policy