0

I am getting following error while trying to create generic HashTable.

The method put(String, capture#2-of ?) in the type Hashtable<String,capture#2-of ?> is not applicable for the arguments (String, int)

I need a HashTable, something like following: HashTable<String, HashTable<String, AnyWrapperType>>

by AnyWrapperType i mean it could be Integer or String or Character or Boolean

I used ? for AnyWrapperType, but i got an error.

I also followed link from where i know what i was doing wrong but could find way out.

    Hashtable<String, Hashtable<String, String>> paramTocol = new Hashtable<>();

    if (standard != null && (!standard.isEmpty())) {
        Hashtable<String, String> temp = new Hashtable<>();
        temp.put(Appconstants.Col_studentinfo_S_Class,
                AvailableClass.getValueByName(standard));
        paramTocol.put("standard", temp);
    }
    if (section != null && (!section.isEmpty())) {
        Hashtable<String, String> temp = new Hashtable<>();
        temp.put(Appconstants.Col_studentinfo_S_Section, section);

        paramTocol.put("section", temp);
    }

Here actual value of standard is Integer in database and value corresponding to section is char. I am given all these values as String and i need to store them in HashTable, So i want some raw hashtable that will hold all these values. None of the type is User-defined

Community
  • 1
  • 1
Kanishka Gupta
  • 217
  • 2
  • 6
  • 17
  • 3
    It's not clear what your existing code looks like, or what you're trying to do with the table afterwards (or why you're not using `HashMap`) – Jon Skeet Jun 25 '13 at 18:53
  • I have added some more description, i hope that will clear my issue – Kanishka Gupta Jun 25 '13 at 19:09
  • Not really - we don't know any of the types involved. What's `Appconstants.Col_studentinfo_S_Section` for example? – Jon Skeet Jun 25 '13 at 19:12
  • `Appconstants.Col_studentinfo_S_Section` is a String which corresponds to column name in database. – Kanishka Gupta Jun 25 '13 at 19:22
  • So everything in your sample code is about strings - where do the wrapper types come in? It would really help if you'd show a short but *complete* program (a console app) which actually demonstrates your problem. Please read http://tinyurl.com/so-hints – Jon Skeet Jun 25 '13 at 19:33

1 Answers1

1

I think you can set the AnyWrapperType to Object. Since all classes in java are directly or indirectly subclass of Object, so instead of setting a generic type you can set the type to Object. When ever you need to get that element you should perform a type-cast.

HashTable<String, HashTable<String, Object>>