Deepa Sobin wrote:In that case, why does the below code fail to add a Number into this list which can hold any super type of Integer?
Deepa Sobin wrote:Hi,
Can you please help me understand why the below code compiles fine
and the below one does not?
Regards
Deepa
Nitesh, it is true that both the IS-A and HAS-A relationships can reduce the amount of code we write. In my opinion, though, the main benefit relates to the principle of cohesion and the ability to write cohesive classes. You will likely find references to the principle of cohesion in your study materials; it basically means that a single class should provide only closely related functionality.Nitesh Nandwana wrote:Matthew i thought about need of HAS-A relationship is only one that is, to allow more specialist classes usage hence reduction in code else i could directly write show() in Car class.
Tommy Delson wrote:
Campbell Ritchie wrote:What is the Unicode value of that apostrophe? Is it \u0027 (') or \u2019 (’)? If you simply push the key, you usually get \u0027.
This code creates a new Integer using the "value" of this.value, calls the toString() method to return a string representation of the Integer, then calls the String class's hashCode() function(which overrides Object's hashCode() function) on that String to create a hash code.Nitesh Nandwana wrote:
Eli Wood wrote:
.
According to hashCode() documentation, it is invoked with object, here in above code how did you invoked and why did you so i am not getting at all.
Nitesh Nandwana wrote:
Eli Wood wrote: since every two equal InstEqual objects will have equal hashcodes.
In my last example, obj1 and obj2 are equal then why their hash code values are not same as you said above.
Nitesh Nandwana wrote:I know that every object has hashcode in integer form as a key to identify that object, and according to documentation of hashCode(), it returns hashCode value of invoking object.Now question is that in my program hashCode() is return the value of instance variable value of obj1 and obj2. those are 2 and 12. Where is the hashcode of objects ?? i am feeling very irritated because i don't want value of variable if i want variable value then simply i can make a get() method and return the variable value then why to use this nonsense hashCode(),I need hashcode please help me to find it .
Nitesh Nandwana wrote:it gives hashCode value when i dont override hashCode() but it ought to override if equals() is overridden and why it gives different hashcode of two equal objects ?.
Kees Jan Koster wrote:Dear Eli,
It may be that Java is trying to allocate a massive chunk all at once and decides that is impossible without ever actually allocating it.
Have you checked the code at the points where the apps throws exeptions? What does it allocate there? Something big?
Also, you gave the JVM 1G, so it will not use (much) more than that. Java uses what you give it. It does not scan the local machine and take what is there.
Kees Jan Koster wrote:Dear Eli,
Well, the memory in task manager is not likely to change much, because that is probably pre-allocated to Java at JVM start. You need to look into the running application at what happens with the heap space.
You can do that with jconsole or visualvm or (my favourite) Java-monitor. Here is what a memory leak looks like when seen through Java-monitor: http://java-monitor.com/forum/showthread.php?t=150