• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

compile-time type checking

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone please suggest how I can improve compile-time type checking in the following piece of code?

 
Vatsa dude
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only solution I can think of is changing <Object, Object> to <String, String> all over the code.. Is that it?
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what types of object you want to store in the map. If you might store anything in the Map, then there is no way to improve it -- what you've defined will store any object/object pair. But, for example, if you know the key is a String, then define the variable as private Map<String, Object> map = new HashMap<String, Object>(); -- the more specific your requirements, the more specific you can be. (By the way, your get() and put() methods don't seem to do anything more than what's provided in the map itself.)
 
Vatsa dude
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, I might have misunderstood the problem. I had to duplicate a class as a Singleton similar to 'MyCache' below called 'SingletonCache'. Can compile-time type checking be improved in the code below? (Except for changing <Object, Object> to specific type like <String,String>

 
Alas, poor Yorick, he knew this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic