0

I am trying to create a BinarySearchTree using generics, but I am bumping into an error. I want my class to extend Number and Implement Comparable. So I declare it this way:

public class BinaryTree<K extends Number implements Comparable<? super K>, E>

But I am getting an error.

File: F:\Java\intro-prog-java\bookClasses\Lab_5\BinaryTree.java [line: 1] Error: > expected

I cannot get whats wrong with it.

1 Answer 1

5

That's the wrong syntax. Try this:

public class BinaryTree<K extends Number & Comparable<? super K>, E>

This syntax is described in the Bounded Type Parameters topic of the Java tutorials on generics as well as §4.4 of the Java Language Specification.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.