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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:46:34+00:00 2026-06-11T22:46:34+00:00

Possible Duplicate: Java Generics, how to avoid unchecked assignment warning when using class hierarchy?

  • 0

Possible Duplicate:
Java Generics, how to avoid unchecked assignment warning when using class hierarchy?

Intellij is giving me the warning below. Not sure how to resolve it, or even if I need to resolve it. The warning details says it only applies to JDK 5, and I am using 6. I am wondering if I need to respond to this, and if so, how?

Method call causing warning

List<T> refObject = cache.getCachedRefObject(cacheKey, List.class);

Method being called

public  <T> T getCachedRefObject(String objectKey, Class<T> type) {
    return type.cast(refObjectCache.get(objectKey));
}

Warning details

Unchecked Assignment
JDK 5.0 only. Signals places where an unchecked warning is issued by the compiler, for example:
    void f(HashMap map) {
        map.put("key", "value");
    }
  • 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-11T22:46:35+00:00Added an answer on June 11, 2026 at 10:46 pm

    Having played with super type tokens for this, I don’t think you can make this type-safe without making extra methods to retrieve collections from your cache and verifying if their contents are of the correct type.

    Your options are:

    1. Doing the above, which seems laborious
    2. Suppress the unchecked cast in client code if you know it’s correct.
    3. Replace the client code with List<?> refObject = cache.getCachedRefObject(cacheKey, List.class);

    The only type-safe variant of these is 3., in that it prevents you from doing operations that the compiler can’t prove are type-safe. The obvious downside is that you might want to do some of these operations anyway.

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

Sidebar

Related Questions

Possible Duplicate: Instantiating a generic class in Java I am studying Generics Java because
Possible Duplicate: Java Generics In Eclipse, I am given warnings for using 'rawtypes' and
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
Possible Duplicate: Java: Rationale of the Object class not being declared abstract Why is
Possible Duplicate: Java: Always override equals? should I override equals function for any class
Possible Duplicate: Java Generics To be more specific, whats the role of the <String>
Possible Duplicate: Java Class.cast() vs. cast operator I am unsuccessfully trying to find out
Possible Duplicate: get type of a generic parameter in java with reflection Java Generics
Possible Duplicate: Is List<Dog> a subclass of List<Animal>? Why aren't Java's generics implicitly polymorphic?
Possible Duplicate: Is List<Dog> a subclass of List<Animal> ? Why aren't Java's generics implicitly

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.