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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:38:33+00:00 2026-05-30T01:38:33+00:00

Now and then in my code I find that I can solve a problem

  • 0

Now and then in my code I find that I can solve a problem by either using a naked generic class or one with wildcards.

I have a design where a class like this:

Class World<T, C> { .... }

definitely in general is making my code cleaner than it would have been without generics.

Yet, sometimes I use

World theWorld;

or sometimes I end up with

World<?, ?> theWorld;

I do this because it seems to be what it takes to make the compiler accept it and my
attempts to avoid them lead me to more casting or inheriting complexity.

It looks ugly and smelly to me and yet I cannot justify the added complexity it looks like I need to introduce to avoid it.

What are some cases (if any) that you believe using a naked or wildcarded generic is acceptable idiomatic Java?

  • 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-30T01:38:35+00:00Added an answer on May 30, 2026 at 1:38 am

    Any time you could use generics but don’t need it in that specific situation. <?> tells the compiler roughly: “I know about generics, but I don’t need the type now”.

    Maybe the type is needed in other situation. E.g. if you have a Set that just stores anything, like a cache, and you just don’t care for the type of the elements at all. At other times you do, when you process specific elements.

    It smells if you use too loosely bound type parameters (like <?> which is quite loose) but try to determine the type afterwards, e.g. with instanceof or some custom type discriminator. Then something was designed poorly.

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

Sidebar

Related Questions

This problem crops up every now and then at work. Our build machine can
I find myself writing SQL code (queries or stored procs) to solve problems that
I have another problem I can't seem to solve..., or find on this site...
Every now and then (ahem...) my code crashes on some system; quite often, my
Every now and then, I bump into syntax that I've seen before, but never
Every now and then I receive a Word Document that I have to display
Every now and then I have a problem with SVN inside eclipse folder gets
A term that I see every now and then is Cyclomatic Complexity. Here on
I can't find any question similar to what I'm looking for, that is why
its been I while since I try to solve that problem, I've already asked

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.