Java generics bound mismatch recursive type

Oleg Nykolyn

I'm having a weird problem I don't understand how to solve. Here is the declaration of the class in which the error is appearing:

public class DList<V extends Comparable<V>> { ...

Down below I have a method which has the following signature:

public DList<DList<V>> split(int steps) { ...

which gives me the specific error

Bound mismatch: The type DList<V> is not a valid substitute for the bounded parameter <V extends Comparable<V>> of the type DList<V>

So far the problem is the following class accepts type V which has an upper limit of Comparable, but the recursive type DList isn't accepted. How can I solve this sort of 'recursion' of types and get rid of the error?

giorgiga

Have DList implement Comparable:

public class DList<V extends Comparable<V>> implements Comparable<DList<V>> {
    @Override public int compareTo(DList<V> other) {
        return 0;
    }
}

then make sure that the substitute for V is well bounded:

public class Other {

    public static <X extends Comparable<X>> DList<DList<X>> split(int steps) {
        return null;
    }

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java generics: Bound mismatch

From Dev

Java generics: Bound mismatch: The type is not a valid substitute for the bounded parameter of the type

From Dev

Java Generics Bound Mismatch Compilation Error

From Dev

Java Stream Generics Type Mismatch

From Dev

Java generics: Bound mismatch.Looking for the valid substitute

From Dev

Java generics: Bound mismatch.Looking for the valid substitute

From Dev

Type mismatch with Java generics and anonymous class

From Dev

Java/Scala Bounded Generics and type inference mismatch

From Dev

Java generics - type mismatch from T to T

From Dev

Scala type mismatch with generics

From Java

Bound mismatch error on generics type argument for a generic class that extends another generic class

From Dev

Java Generics argument mismatch

From Dev

Java generics. Type mismatch: cannot convert from object to

From Dev

Java generics : Type mismatch: cannot convert from Integer to K

From Dev

Java generics. Type mismatch: cannot convert from object to

From Dev

abstract recursive generic causes bound mismatch

From Dev

Scala: Type mismatch with nested generics

From Dev

Kotlin generics inheritance - Type mismatch

From Dev

Bound mismatch: type is not a valid substitute for the bounded parameter

From Dev

Bound Mismatch Error: The type is not a valid substitute

From Dev

Bound mismatch: The type Foo is not a valid substitute

From Dev

Type mismatch in variable assignment to generics based variable

From Dev

Type mismatch in variable assignment to generics based variable

From Dev

Java: Recursive generics compiler error

From Dev

Java Generics - Type parameter `K` is not within its bound; should implement X

From Dev

Type mismatch in java

From Dev

Java: Class Type mismatch

From Dev

Parameterized Type Mismatch in Java

From Dev

Java F-Bound types with generics

Related Related

  1. 1

    Java generics: Bound mismatch

  2. 2

    Java generics: Bound mismatch: The type is not a valid substitute for the bounded parameter of the type

  3. 3

    Java Generics Bound Mismatch Compilation Error

  4. 4

    Java Stream Generics Type Mismatch

  5. 5

    Java generics: Bound mismatch.Looking for the valid substitute

  6. 6

    Java generics: Bound mismatch.Looking for the valid substitute

  7. 7

    Type mismatch with Java generics and anonymous class

  8. 8

    Java/Scala Bounded Generics and type inference mismatch

  9. 9

    Java generics - type mismatch from T to T

  10. 10

    Scala type mismatch with generics

  11. 11

    Bound mismatch error on generics type argument for a generic class that extends another generic class

  12. 12

    Java Generics argument mismatch

  13. 13

    Java generics. Type mismatch: cannot convert from object to

  14. 14

    Java generics : Type mismatch: cannot convert from Integer to K

  15. 15

    Java generics. Type mismatch: cannot convert from object to

  16. 16

    abstract recursive generic causes bound mismatch

  17. 17

    Scala: Type mismatch with nested generics

  18. 18

    Kotlin generics inheritance - Type mismatch

  19. 19

    Bound mismatch: type is not a valid substitute for the bounded parameter

  20. 20

    Bound Mismatch Error: The type is not a valid substitute

  21. 21

    Bound mismatch: The type Foo is not a valid substitute

  22. 22

    Type mismatch in variable assignment to generics based variable

  23. 23

    Type mismatch in variable assignment to generics based variable

  24. 24

    Java: Recursive generics compiler error

  25. 25

    Java Generics - Type parameter `K` is not within its bound; should implement X

  26. 26

    Type mismatch in java

  27. 27

    Java: Class Type mismatch

  28. 28

    Parameterized Type Mismatch in Java

  29. 29

    Java F-Bound types with generics

HotTag

Archive