On Apr 26, 2005, at 6:27 PM, Satoru Moriwaki wrote:
Hi,
How much does casting really affect the performance
(time and space) in Java?
I recall something like 5 for time and 9 for space (or I could have
those backwards).
I've read a few articles on the net and most of them
said that the casting is really cheap in most cases.
Well it isn't a NOP by any means (it has to check to insure the cast
requested is safe / allowed and throw a cast exception if not) but it
is likely one of critically / heavily optimized aspects of a JVM / JIT.
I use Apple's WebObjects and many classes in WebObjects
return an Object type and casting is often necessary.
Don't look now but all of Java's collection classes return and take
Object as well.
In other words it is a reality of Java, don't worry about it unless
when profiling you see a performance issue that can alleviated by
avoiding it (not saying you should go out cast like mad for the fun of
it).
Note Java 5 (aka 1.5) has generics [1] to help reduce the overhead of
typing all those casts in your code (assuming you like its syntax,
personally I am still trying to like it... really really I am). Also
related is autoboxing [2] for the pesky primitive types.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden