aspose file tools*
The moose likes Beginning Java and the fly likes compile-time type checking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compile-time type checking" Watch "compile-time type checking" New topic
Author

compile-time type checking

Vatsa dude
Greenhorn

Joined: Apr 29, 2009
Posts: 22
Can anyone please suggest how I can improve compile-time type checking in the following piece of code?

Vatsa dude
Greenhorn

Joined: Apr 29, 2009
Posts: 22
Only solution I can think of is changing <Object, Object> to <String, String> all over the code.. Is that it?
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
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

Joined: Apr 29, 2009
Posts: 22
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>

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compile-time type checking