Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
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.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!