-2

For example,

public interface Foo<T extends Blackness, S extends T & Whiteness> { }

Error: Type parameter cannot be followed by other bounds

KeepAtIt
  • 163
  • 12

1 Answers1

0

T extends Blackness and S extends T so S inherently extends Blackness. The only other contingency is that S must also extends Whiteness. Because of this restriction, S must be an extension of T but also implement the functionality of Whiteness. Because of this, you will likely have to provide the type T. It's not possible for S to have multiple bounded types, which is why a sub-interface is required that implements both. What you're trying to do doesn't make logical sense. Refer to this.

    public interface Foo<T extends Blackness, S extends BlackAndWhiteness<T>> {

    }

    public interface BlackAndWhiteness<T extends Blackness> extends Whiteness, Blackness {
        
    }

    interface Blackness {

    }

    interface Whiteness {

    }
Jason
  • 5,154
  • 2
  • 12
  • 22
  • Got it. So basically, the error is telling you that you need another interface that combines the two. – KeepAtIt Aug 26 '20 at 16:20
  • 1
    Precisely, you simply need to allow another interface to inherit both of them. – Jason Aug 26 '20 at 16:21
  • Actually, I've had a sleep on this, and your answer actually doesn't answer the question, please don't take offense. It's just that I'm looking for the second generic to not only inherit from the first but also have it's own interfaces. A duel interface is not what I am seeking. – KeepAtIt Aug 27 '20 at 14:49
  • 1
    Updated, hope that helps. – Jason Aug 27 '20 at 15:13
  • Your code example helped me come to a conclusion about the code I'm working on, so thank you. However, the example is about wildcards, so I'm guessing you are implying that even if you state the type and have the other type inherit it, the compiler can't be sure of something. – KeepAtIt Aug 27 '20 at 21:38
  • I honestly don't understand StackOverflow, this was a legitimate question on generics, which can get quite confusing for the experienced programmer, yet it gets downed completely and I lose my privileges to ask questions. – KeepAtIt Aug 28 '20 at 18:08
  • 1
    I didn't downvote your question. I'm not sure what the requirements are anymore to ask questions but i'm sure if you answer a few questions you can get it back in no time. – Jason Aug 28 '20 at 19:00