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

  • SEARCH
  • Home
  • 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 7559371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:37:06+00:00 2026-05-30T12:37:06+00:00

I created small utility which helps me sort my map by values (based on

  • 0

I created small utility which helps me sort my map by values (based on one of the StackOverflow answers to give credit):

public static <K, V extends Comparable> Map<K, V> sortMapByValues(Map<K, V> original) {
    final ValueComparator<K, V> comparator = new ValueComparator<K, V>(original);
    final Map<K, V> sorted = new TreeMap<K, V>(comparator);
    sorted.putAll(original);

    return sorted;
}

And the ValueComparator:

static class ValueComparator<K, V extends Comparable<V>> implements Comparator<K> {
    private final Map<K, V> base;

    public ValueComparator(Map<K, V> base) {
        this.base = base;
    }

    public int compare(K a, K b) {
        return base.get(b).compareTo(base.get(a));
    }
}

Now this works pretty well when in my IntelliJ 10 IDE, the code runs and do what I expect.

But if I try to build the project by maven from command line I get following error:

type parameter V is not within its bound

The error is said to be on the first line of the sortMapByValues() method

I am using JDK 6 in my IDE and my maven compiler plugin is set to 1.6 as well.

Any tips appreciated

  • 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-05-30T12:37:08+00:00Added an answer on May 30, 2026 at 12:37 pm

    I guess it is because of:

    V extends Comparable (in sortMapByValues) and V extends Comparable<V> in class ValueComparator.

    Change the first also to V extends Comparable<V>

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

Sidebar

Related Questions

I've created a small PyQt based utility in Python that creates PNG graphs using
I have created a small application which opens,reads and creates Excel files. The app
we're building a cross-platform utility which must have a small footprint. We've been pulling
I've created a small Activity which is capable of loading two different HTML strings
I have created small test web application which makes use of LINQ to SQL.
I was created one small business application..Here I got the data from server and
I recently built a small, one-file Haskell utility to be included in 'tools' section
I've created a small utility function for string conversion so that I don't have
I've written a small utility class for C++11 which I use as a scope
I've created small database under SQL Server 2008 . Now i wanted to move

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.