Generic Binary Search Tree Java type argument is not within bounds

Riek Rudolph

I did the following binary search tree but it doesn't work... need help

class Tree<ContentType extends Comparable<ContentType>>{


  Node node;
  public Tree(){
    node = null;
  }
  public Tree(ContentType pContent){
    node = new Node<ContentType>(pContent);
  }
  public Tree(ContentType pContent, Tree pLeftTree, Tree pRightTree){
    node = new Node(pContent);
    node.setLeftTree(pLeftTree);
    node.setRightTree(pRightTree);
  }
  public boolean isEmpty(){
    ...
  }

  public void insert(ContentType pContent){
    ...
  } 

  public ContentType search(ContentType pContent){
    ...
  }

  public void delete(ContentType pContent){
    ...
  }
  public ContentType getContent(){
    ...
  }


...      

    private class Node<ContentType>{
        Tree left = null;
        Tree right = null;
        ContentType content = null;


        public Node(ContentType pContent){
          content=pContent;
          left = new Tree();
          right = new Tree();

        }

        ... 

    }


}

Now it tells me

type-variable Content-Type#1 is not within bounds of type-variable Content-Type#2.

Thanks for all help

benson

Here's the fully fixed class file - make sure to specify the generic types when declaring all instances of a type!

class Tree<ContentType extends Comparable<ContentType>>{

    // here
    Node<ContentType> node;

    public Tree(){
        node = null;
    }

    public Tree(ContentType pContent){
        node = new Node<ContentType>(pContent);
    }

    // each time Tree is used, it should be typed!
    public Tree(ContentType pContent, Tree<ContentType> pLeftTree, Tree<ContentType> pRightTree){
        // same with Node!
        node = new Node<ContentType>(pContent);
        node.setLeftTree(pLeftTree);
        node.setRightTree(pRightTree);
    }

    //Node needs to be typed with the exact same type as Tree!
    private class Node<ContentType extends Comparable<ContentType>>{
        // Typed Tree!
        Tree<ContentType> left = null;
        Tree<ContentType> right = null;
        ContentType content = null;


        public Node(ContentType pContent){
            content=pContent;
            left = new Tree<ContentType>();
            right = new Tree<ContentType>(); 
        }

        public void setLeftTree(Tree<ContentType> tree) {
            left = tree;
        }

        public void setRightTree(Tree<ContentType> tree) {
            right = tree;
        }
    }
}

And to compile w/o warnings:

~ bfung$ javac -version
javac 1.8.0_40
~ bfung$ javac Tree.java
~ bfung$

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 Generic Binary Search Tree cannot compare T types

From Dev

Generic Binary Search - JAVA -

From Dev

Generics; Type argument is not within its bounds

From Java

How to fix "type argument S is not within bounds of type-variable E" in Java

From Java

What are the formal conditions for a wildcard parameter in a Java generic type to be within its bounds?

From Java

Generic Binary Search Tree Implementation in Java - calling generic methods, and cast exceptions

From Dev

Is Valid Generic Binary Search Tree with Recursion

From Java

remove method for generic type binary search tree result in stack overflow problem

From Dev

Java Binary Search Word Tree

From Java

Binary Search Tree - Java Implementation

From Dev

constructing a binary search tree in java

From Dev

Binary Search Tree Cloning - Java

From Java

Enforcing Multiple Generic Bounds in Java Return Type

From Java

Java Builder pattern with Generic type bounds

From Dev

Scala type bounds and Java generic interop

From Dev

Java Generic Wildcard breaks type bounds

From Dev

How to make a Binary Search Tree a Complete Binary Search Tree in Java?

From Android

Type argument is not within its bounds Expected: Parcelable Found: String

From Java

Generic type argument in java generics

From Dev

Java generic method type argument

From Dev

Generic argument type matching in java

From Java

Generic binary search tree isn't adding new nodes correctly (Java)

From Dev

Java Making a binary search tree generic (it works but I know I'm not doing it right)

From Dev

Binary search bounds

From Dev

How to define the type of a Binary Search Tree in Julia?

From Dev

Binary search tree boolean return type

From Dev

Writing a generic iterator in Java for Binary Tree

From Dev

Issue with generic type bounds

From Dev

Binary Tree, Binary Search Tree, Binary search

Related Related

  1. 1

    Java Generic Binary Search Tree cannot compare T types

  2. 2

    Generic Binary Search - JAVA -

  3. 3

    Generics; Type argument is not within its bounds

  4. 4

    How to fix "type argument S is not within bounds of type-variable E" in Java

  5. 5

    What are the formal conditions for a wildcard parameter in a Java generic type to be within its bounds?

  6. 6

    Generic Binary Search Tree Implementation in Java - calling generic methods, and cast exceptions

  7. 7

    Is Valid Generic Binary Search Tree with Recursion

  8. 8

    remove method for generic type binary search tree result in stack overflow problem

  9. 9

    Java Binary Search Word Tree

  10. 10

    Binary Search Tree - Java Implementation

  11. 11

    constructing a binary search tree in java

  12. 12

    Binary Search Tree Cloning - Java

  13. 13

    Enforcing Multiple Generic Bounds in Java Return Type

  14. 14

    Java Builder pattern with Generic type bounds

  15. 15

    Scala type bounds and Java generic interop

  16. 16

    Java Generic Wildcard breaks type bounds

  17. 17

    How to make a Binary Search Tree a Complete Binary Search Tree in Java?

  18. 18

    Type argument is not within its bounds Expected: Parcelable Found: String

  19. 19

    Generic type argument in java generics

  20. 20

    Java generic method type argument

  21. 21

    Generic argument type matching in java

  22. 22

    Generic binary search tree isn't adding new nodes correctly (Java)

  23. 23

    Java Making a binary search tree generic (it works but I know I'm not doing it right)

  24. 24

    Binary search bounds

  25. 25

    How to define the type of a Binary Search Tree in Julia?

  26. 26

    Binary search tree boolean return type

  27. 27

    Writing a generic iterator in Java for Binary Tree

  28. 28

    Issue with generic type bounds

  29. 29

    Binary Tree, Binary Search Tree, Binary search

HotTag

Archive