This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Is this a good practice...  RSS feed

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return type of the getBusinessObjects() is 'Object', but I am returning the java.util.Collection, sometimes Hashtable...
Is this a good practice??
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally speaking: No.
What is the problem you try to solve?
 
Bala Krishniah
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you say its incorrect. Could you please explain.
And the reason I am using the above logic is....
I was reading the database and storing the data, storing is a class object and storing those objects in a Vector and was always returning a Vector from my getBusinessObject() method...
CODE]
Collection getBusinessObject(){}
[/CODE]
But later on, I wanted to return two sets of vector objects from a the getBusinessObject() method. So I thought of putting the vectors in a Hashtable and return it, but couldn't since the return type extected is Collection. I could have added two vectors and returned a single vector...
but then I only have to depend on the position of the object in a vector.
Hence I thought of chaning the return type of getBusinessObject() to Object, so that I can return any type.
Please comment.
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Vectors causes a lot of overhead and over transferring the same over the wire can be killing. Please try to eliminate the use of Vectors as a means of transferring objects as far as possible. It starts showing once the hit count increases
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandy ind said:


Using Vectors causes a lot of overhead...


I couldn't agree more. We recently did a performance analysis of our app (about 150,000+ lines of code). It turned out that 80% of all the running time was atrributed to a single line of code where an element was searched in a vector. After we replaced the vector with the other collection type (very few lines of code), our app ran 4 times faster (down from 4 minuets to 1)!
Eugene Kononov.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!