It's an object dummy!
That's been the answer to several of my Java holdups.
First, I had a hashmap holding Strings keys to Integer prices. When I was getting the prices back out I had a little difficulty. They had to be explicitly downcast to Integer from Object, then to assign them to an int primitive I had to use the .intValue() method.
Then when trying to compare two strings I quickly realized that == compares to references. Strings are objects, not primitives, so they logically have a comparisson method, equals().
First, I had a hashmap holding Strings keys to Integer prices. When I was getting the prices back out I had a little difficulty. They had to be explicitly downcast to Integer from Object, then to assign them to an int primitive I had to use the .intValue() method.
Then when trying to compare two strings I quickly realized that == compares to references. Strings are objects, not primitives, so they logically have a comparisson method, equals().
0 Comments:
Post a Comment
<< Home