wood burning stoves 2.0*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 1456
    
    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: 3054
    
  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: 1456
    
    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: 1456
    
    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: 1456
    
    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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Return type doubt
 
Similar Threads
findByCriteria returns long[]
returntypes
ArrayList conversion
Trying to pull out Unique values from database
Split String Based On String Length