Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:20:49+00:00 2026-06-14T12:20:49+00:00

I was given a generic binary search tree class with the following declaration: public

  • 0

I was given a generic binary search tree class with the following declaration:

public class BST<K extends Comparable<K>, V>

I was asked to write a method that reverses the BST such that the values become the keys and keys become values. When I call the following method (defined in the class given)

reverseDict.put(originalDict.get(key), key); 

I get the following two error messages from Netbeans:

Exception in thread “main” java.lang.RuntimeException: Uncompilable source code – Erroneous sym type: BST.put

And also:

no suitable method found for put(V,K) method BST.put(BST<K,V>.Node,K,V) is not applicable (actual and formal argument lists differ in length) method BST.put(K,V) is not applicable (actual argument V cannot be converted to K by method invocation conversion) where V,K are type-variables:

V extends Object declared in method <K,V>reverseBST(BST<K,V>)

K extends Comparable<K> declared in method <K,V>reverseBST(BST<K,V>)

From what the error messages are telling me, since my values do not extend Comparable I am unable to use them as keys. If I am right, how can I get around that without changing the class given (maybe a cast)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:20:50+00:00Added an answer on June 14, 2026 at 12:20 pm

    I think the problem is that you need a V extends Comparable<V> in order to use it as key, but you have only a V without bounds. I think you need to write a static method like..

    public static <A extends Comparable<A>, B extends Comaparable<B>> 
        BST<B,A> invert(BST<A,B> bst) {...}
    

    .. in order to ensure that additional condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following generic interface and implementing class: public interface IRepository<T> { // U
Given the generic method: <T> List<T> getGenericList(int i) {...} the following code compiles without
Given the following program: using System; using System.Collections.Generic; namespace ConsoleApplication49 { using FooSpace; class
Given these classes: using System.Collections.Generic; namespace FluentMappingsQuestion { public class Entity { public virtual
Given a generic tree based (Java) data model. Let's say abstract class XModel {
Given a generic class definition like public class ConstrainedNumber<T> : IEquatable<ConstrainedNumber<T>>, IEquatable<T>, IComparable<ConstrainedNumber<T>>, IComparable<T>,
Given a generic attribute class: public class Attribute<T> { string Name { get; set;
Given the following example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization.Formatters.Binary;
Given this generic serialization code: public virtual string Serialize(System.Text.Encoding encoding) { System.IO.StreamReader streamReader =
Given a generic class: class MyClass ( private List l = new LinkedList <String>();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.