Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compile-time type checking

 
Vatsa dude
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • 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
  • 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>

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic