Prasad Gunaratne

Greenhorn
+ Follow
since Jun 13, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Prasad Gunaratne

why can't author of the topic move it somewhere else if required?
21 years ago
Why does log4j output statement in onMessage() method of a Message Driven Bean appear as ....(?:?).... .?
I am expecting the classname and the line number where ? marks appear.
21 years ago
Jim,
Thanks a lot for feedback. i think you are right about compiler optimization of the piece of code I've written.
Because I recall similar behaviour for the same kind of test code some time back for a different purpose.
I got results as casting 10-20 ms and toString() 20-40 ms (for one million iterations).
For all the other reasons you described, casting looks the way to go.
But still there is an unanswered question.
Does the casting creates a new Object? Looking at the figures of our tests it might not be the case,
as it is very fast, yet how can we know for sure?
Prasad
21 years ago
Object is known to be a String. So that is out of question. To my suprise the following code shows that casting might be faster indeed. But only just. May be there is no difference after all even though faster method is required for me. I deciced to use casting. Hope i got test code right!


[ September 19, 2002: Message edited by: Prasad Gunaratne ]
21 years ago
Hi,

Which operation casting or toString() is faster when converting Object reference to a String?
e.g
Object obj = getObject();
String value;
(1). value = (String)obj;
(2) if(obj!=null)
value= obj.toString()

Which is prefered? (1) or (2)
thanks
Prasad
21 years ago
Is it possible to have structs user guide in .pdf version or printer friendly format?
thanks
Prasad
21 years ago