aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Return type doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Return type doubt" Watch "Return type doubt" New topic
Author

Return type doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

There is compile error in below program "Incompatible type", how to resolve it without changing return type "Object" for method "returnArray".


Tell the difficulties that i am difficult.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

saloni jhanwar wrote:how to resolve it without changing return type "Object" for method "returnArray"

hint : typecasting


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

You cannot do without adding an explicit cast.


Mohamed Sanaulla | My Blog
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Anayonkar Shivalkar wrote:
saloni jhanwar wrote:how to resolve it without changing return type "Object" for method "returnArray"

hint : typecasting


Tried, but i think there is syntax problem

Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Tried, but i think there is syntax problem wrote:Tried, but i think there is syntax problem

You should typecast it during the assignment itself :

Please refer to my next post
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

By the way, in your second code, I see two references with same name obj

This would also work:
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Anayonkar Shivalkar wrote:
Tried, but i think there is syntax problem wrote:Tried, but i think there is syntax problem

You should typecast it during the assignment itself :



Thanks
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

You are welcome.

By the way, its not necessary to typecast it during the assignment. Only problem with your second code was duplicate variable name.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Return type doubt