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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:16:44+00:00 2026-05-25T11:16:44+00:00

I have a class A like this: public class A<T extends Number> { ….

  • 0

I have a class A like this:

public class A<T extends Number>
{
 ....
}

In another class I have this method:

public Hashtable<String, A> createAHashtable()
    {
        Hashtable<String, A> hTable = new Hashtable<String, A>();

        return hTable;
    }

There is a warning for parameter A because it is generic class. So should I do this:

public Hashtable<String, A <?>> createAHashtable()
        {
            Hashtable<String, A<?>> hTable = new Hashtable<String, A<?>>();

            return hTable;
        }

or do this:

public Hashtable<String, A <? extends Number>> createAHashtable()
{
Hashtable<String, A<? extends Number> hTable = new Hashtable<String, A<? extends Number>();

return hTable;
}

or ….???

EDIT:

Tried this (as suggested by Dilum)

public <T extends Number> Hashtable<String, A<T>> createAHashtable()
    {
        Hashtable<String, A<T>> hTable = 
                new Hashtable<String, A<T>>();
        A<Float> constraint = new A<Float>();
        hTable.put("test", constraint);

        return hTable;
    }

But it is invalid to “put” my Float A.

Maybe the wildcard is the way to go.

EDIT 2:

Based on Dilum’s suggestion, the following code (cast to A when put a Float A into the Hashtable) has no error but warning it is unsafe cast. Why we need the cast?

public <T extends Number> Hashtable<String, A<T>> createAHashtable()
        {
            Hashtable<String, A<T>> hTable = 
                    new Hashtable<String, A<T>>();
            A<Float> constraint = new A<Float>();
            hTable.put("test", (A<T>)constraint);

            return hTable;
        }
  • 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-25T11:16:45+00:00Added an answer on May 25, 2026 at 11:16 am

    Try this:

    public <T extends Number> Hashtable<String, A<T>> createAHashtable() {
      return new Hashtable<String, A<T>>();
    }
    

    Say you did want to pre-fill with a key-value pair, try:

    public <T extends Number> Hashtable<String, A<T>> createAHashtableWithEntry(String key, T value) {
      Hashtable<String, A<T>> ht = return new Hashtable<String, A<T>>();
      ht.put(key, new A<T>(value));
      return ht;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method signature: public int nrOfEntities(Class<? extends MailConfirmation> clazz, User user, String
I have a number of classes that look like this: class Foo(val:BasicData) extends Bar(val)
Hi have one class like this import java.util.ArrayList; public class MobilePhone { private String
Ok, I have a class like this: public class Foo extends Sprite { public
I have a base class like this class Base { public var space:Number; }
I have a class like this: public class Stretcher : Panel { public static
I have a class like this: public class myClass { public List<myOtherClass> anewlist =
I have a class like this public class foo { private void getThread() {
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
i am having a strange problem, i have a static class like this public

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.