|
Incoherence posted:1. First rule of hashCode(): if two objects have the same hashCode(), equals() should return true on them as well. The converse is usually the part people trip over (overriding equals() but not hashCode()). I'm not sure you keep that invariant, which you should do. Unless I'm reading this wrong, you got it backwards. This is a valid, but stupid implementation of a hashcode. code:
logically equivalent but put in a different way: if a.hashcode() != b.hashcode() then a.equals(b) should be false.
|
# ¿ Apr 23, 2008 02:27 |
|
|
# ¿ Apr 27, 2024 11:59 |
|
Incoherence posted:I didn't get it backwards (both directions are equally true), but I should have been more clear about that being an if-and-only-if statement: Sorry. That't not correct though. Multiple values can have the same hash code. You want to minimize collisions, but they will happen. These are both valid hash functions but wouldn't be if a.hashcode()==b.hashcode() -> a.equals(b) return 0; \\1.hashcode() == 2.hashcode but 1 != 2 return x % 35; \\ 1.hashcode() == 36.hashcode() but 36 != 1 java posted:
poopiehead fucked around with this message at 03:54 on Apr 23, 2008 |
# ¿ Apr 23, 2008 03:48 |
|
It sounds like what you're doing is valid. Try highlighting the variable that isn't getting updated right and pressing ctrl+shift+I and see if it gives you a more up to date picture. You could also try showing the Display view and writing a line of code to access one of the members in question and then hit the run button or highlight + ctrl+shift+I.
|
# ¿ May 5, 2008 00:06 |
|
My guess would be ASP/VBScript ...could be ASP.NET/VB also though but not likely since there's a raw form tag... poopiehead fucked around with this message at 00:54 on May 22, 2008 |
# ¿ May 22, 2008 00:51 |
|
It looks like it will call the method repeatedly until it throws an exception, which is kind of weird. The point of reflection here might just be to act as a function pointer which is kind of awkward to do in Java. This method can work with any static void method with no arguments..... but I don't think there's really enough information there to actually know what's going on. It might be clearer with the full code of the method and where it's being called.
poopiehead fucked around with this message at 02:14 on May 27, 2008 |
# ¿ May 27, 2008 02:12 |
|
LinkedHashMap
|
# ¿ Jun 1, 2008 14:13 |
|
Am I missing something here? Just want to see if I'm missing something obvious. This is an excerpt of a non-blocking queue implementation. code:
I know this is basic java, but I doubt myself when it's in an article by Brian Goetz on a popular site and written 2 years ago.
|
# ¿ Jun 21, 2008 05:51 |
|
Thanks for confirming that I'm not crazy. The OpdenJDK implementation looks ok. tail and head are volatile read-only fields. They use this special atomic reference class that handles all of the writes to the fields using reflection. Hopefully that makes you feel better
|
# ¿ Jun 21, 2008 14:03 |
|
zootm posted:When I was looking at the OpenJDK one, it looked a lot like both head and tail fields were initialised to the same container instance, and the container instances used the reflection thing to update their "next" and "item" fields. Confusing anyway! Yeah it's weird. too lazy to copy and paste, but it was like this, more or less.... code:
|
# ¿ Jun 21, 2008 23:32 |
|
Entheogen posted:why do you need @Override anyway? I never used it, and never got any warnings from javac compiler. For one thing, it prevents you from changing the signature of a method that was meant to override another. Prevents you from doing something like changing your toString() method to toString(String formatString). Your code will compile fine without it, but it's a useful tool. It also makes the code more readable because you know at a glance that it is overriding. In C#, it's even part of the method signature. On using @Override with interfaces, it will actually cause a compiler error in Java 5, but will not in Java 6. poopiehead fucked around with this message at 01:20 on Jun 27, 2008 |
# ¿ Jun 27, 2008 01:13 |
|
|
# ¿ Apr 27, 2024 11:59 |
|
Alan Greenspan posted:I have like 50-75 classes that need to have the same 9 lines: This probably isn't the case, but if the classes can reasonably have a common base class or maybe can be grouped into a few common base classes, it's pretty easy. But unless they genuinely have something else in common, this would probably be a bad idea. code:
poopiehead fucked around with this message at 06:02 on Jul 2, 2008 |
# ¿ Jul 2, 2008 05:50 |