aspose file tools*
The moose likes Beginning Java and the fly likes writing methods  which returns different Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writing methods  which returns different Objects " Watch "writing methods  which returns different Objects " New topic
Author

writing methods which returns different Objects

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Dear all,
I had written one function which Returns Object and takes parameter as Object also


Here the function is working fine and while calling the function i had to type cast the Value which the function returns Object
i want to alter my code such that i need not to type cast in the calling function is this possible and i had also gone through wild cars also there it suits for objects which extends Number but here im using Vectors and String also so please tell me the way to com out of this


Creativity is nothing but Breaking Rules
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38873
    
  23
Will that actually compile? It doesn't look at all good to me. You might do well to find the Class.forName("foo.bar.Class").newInstance() idiom. But that (I think) requires a no-arguments constructor.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38873
    
  23
Or maybe a Map<String Class><?>> which returns the Class object for a particular name?
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Ya its compiled and running and currently i'm type casting the in the calling function but i want to make not to type cast for all the four objects
Aneesh Vijendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 125
Why do you want to do this?



also does the same thing.

Where ever you call any of these methods, you need to do a typecast as the signature is still Object.


Moreover:


wont compile for sure, rather it should be



Cheers
Aneesh
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Sorry i had used


also does the same thing.

Where ever you call any of these methods, you need to do a typecast as the signature is still Object.


I'm using different logic based upon the Objects(Integer,Boolean,Vector ,String)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38873
    
  23
santhosh.R gowda wrote:Sorry i had used . . .
I suspected that, but we can't be sure. Please read this FAQ.
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296


Here i'm returning the Object as a return value and in my calling method i want to type cast as per my requirement
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing methods which returns different Objects