Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Casting.. is there overhead?

John Bateman
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know how much overhead there is when you cast objects. The reason is because I've created a controller class that handles requests to get certain objects (sort of like a factory). If I make this classes get method return Objects all the time then I have to always make the calling class cast the returned Object into the type it needs (Ticket, User, Prize whatever).
Now I understand if I do this in a few spots it's not soo bad, but what if I now have a site that uses many controllers with many requests that use this Object return type all having to be casted into their respective types? Is it safer to just use the 'most generically-specific class' whenever I can instead of "Object".
Definition: By "generically-specific" I mean using Collection return type instead of Object when dealing with a method that COULD return a HashSet, Vector or an ArrayList.
Thanks in advance.
[This message has been edited by John Bateman (edited March 13, 2001).]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic