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 7771207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:35:36+00:00 2026-06-01T16:35:36+00:00

I’m trying to code something with generics, but cannot seem to figure out how

  • 0

I’m trying to code something with generics, but cannot seem to figure out how to get around using a @SuppressWarnings.

I have the following:

/**
 * Cache to know which pool provided which object (to know where to return object when done)
 */
private Map<Object, ObjectPool<?>> objectPoolCache = new ConcurrentHashMap<Object, ObjectPool<?>>();

/**
 * Returns a borrowed pool object to the pool
 * @param o
 * @throws Exception
 */
public void returnToPool( Object o ) throws Exception {
    // safety check to ensure the object was removed from pool using this interfact
    if( !objectPoolCache.containsKey(o))
        throw new IllegalStateException("Object is not in pool cache.  Do not know which pool to return object to");

    // get the object pool
    ObjectPool pool = objectPoolCache.remove(o);

    // return the object to the pool
    pool.returnObject(o);
}

Right now, I get a warning that ObjectPool pool is a raw type and a Type Safety warning on the return statement.

My concept is the following; I’m looking to make a map of object/pool pairs such that I know which pool an object was retrieved from in order to know to which pool to return the object.

The ObjectPool can be an ObjectPool of any type of object; there is no specific supertype required.

I’ve tried using <? extends Object>, but I’m not entirely sure how to use it without causing compile errors. Just replacing the <?> with <? extends Object> runs me into a problem that my method uses an Object as a parameter, which is inconsistent with a pool that extends an Object.

Any assistance would be appreciated.

Thanks!

Eric

  • 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-01T16:35:37+00:00Added an answer on June 1, 2026 at 4:35 pm

    This is not doable without @SuppressWarnings, just because Java’s type system is not strong enough to express the constraint that your Map maps any object of type T to some ObjectPool<? super T>.

    Generics are designed to prove the type-safety of a wide variety of operations in Java, but they’re just not powerful enough for what you’re doing. You just have to tell the compiler to “trust that you know what you’re doing,” which is what @SuppressWarnings is for.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has

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.