About Question com.enthuware.ets.scjp.v6.2.181 :
Moderator: admin
-
- Posts: 8
- Joined: Tue May 14, 2013 12:27 am
- Contact:
About Question com.enthuware.ets.scjp.v6.2.181 :
Please explain the following requirement for LinkedHashMap as mentioned in the explanation of this question:
"you cannot simply insert the key-value again (without removing it) because a reinsertion operation does not affect the position of the pair"
what is the difference between 1st time insertion and reinsertion of the key, as relating to the position of the pair in the LinkedHashMap?
"you cannot simply insert the key-value again (without removing it) because a reinsertion operation does not affect the position of the pair"
what is the difference between 1st time insertion and reinsertion of the key, as relating to the position of the pair in the LinkedHashMap?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
For example, If an element is at 3rd position (out of 10, say) and if you reinsert it, it will still be at 3rd position. If you remove it and then insert it, it will be at 10th position.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Fri Sep 11, 2015 9:13 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
Why isn't TreeMap a good candidate for this? It would store the results in a sorted order (we can sepecify LastAccessedTime as a ordering criteria).
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
Where would the last accessed time be stored? There is no such field in the objects that you are storing.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sat Aug 31, 2019 3:19 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
This question seems a bit tricky because if you can modify the class, as described by @ACV001, it's actually simpler to achieve the solution than using a LinkedHashMap, since you wouldn't need to remove the object from the map and add it back.
It would be less confusing if the question statement said that we don't have access to that other class.
It would be less confusing if the question statement said that we don't have access to that other class.
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
Which other class??
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sat Aug 31, 2019 3:19 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
Class of the objects being cached.
And by "access", I mean being able to modify it.
And by "access", I mean being able to modify it.
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
Why would the developer of the cache class have the ability to modify the class of the cached objects? The cache developer wouldn't even know what type of objects will be cached. Would you expect the developer of HashMap to able to modify the class of the objects that will be stored in the HashMap? No, right?
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sat Aug 31, 2019 3:19 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
That's true if we want to develop a generic class that could cache objects of any class.
I was thinking of a class to cache objects of a specific class (or set of classes) which we would have control.
Thanks for your thoughts.
I was thinking of a class to cache objects of a specific class (or set of classes) which we would have control.
Thanks for your thoughts.
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.181 :
I understand that the discussion has ended from your side but I am posting this response in case another reader goes through this thread.
>I was thinking of a class to cache objects of a specific class
Even if that were the case, you still wouldn't want to modify that class to facilitate caching. The business of caching is entirely orthogonal to the business of the class of the objects being cached and making the cache class depend on the code of the cached object class would be a violation of separation of concerns. It is tight coupling. An absolute no no.
HTH,
Paul.
>I was thinking of a class to cache objects of a specific class
Even if that were the case, you still wouldn't want to modify that class to facilitate caching. The business of caching is entirely orthogonal to the business of the class of the objects being cached and making the cache class depend on the code of the cached object class would be a violation of separation of concerns. It is tight coupling. An absolute no no.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 150 guests