Moneyball Casting

There is a very good reason for why the Michigan State Spartans star in the annual Moneyball Pro-Am every summer. The 20th annual Moneyball Pro-Am kicked off last week at Holt High School, less than ...

moneyball casting 1 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

Casting to void* removes all type safety. If you use reinterpret_cast or static_cast to cast from a pointer type to void* and back to the same pointer type, you are actually guaranteed by the standard that the result will be well-defined.

moneyball casting 2 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

is there a possibility that casting a double created via Math.round() will still result in a truncated down number No, round() will always round your double to the correct value, and then, it will be cast to an long which will truncate any decimal places. But after rounding, there will not be any fractional parts remaining. Here are the docs from Math.round(double): Returns the closest long to ...

Casting can be used to clearly state that you are calling a child method and not a parent method. So in this case it's always a downcast or more correctly, a narrowing conversion.

Essentially casting will not change anything in how it works, it does exactly what it says, allocates memory, and casting does not effect it, you get the same memory, and even if you cast it to something else by mistake (and somehow evade compiler errors) C will access it the same way. Edit: Casting has a certain point.

moneyball casting 5 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

For casting to a class type, it is known exactly how many superclasses there are until you hit java.lang.Object, so the type can be read at a constant offset from the type pointer (actually the first eight in HotSpot).