Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return type doubt

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is compile error in below program "Incompatible type", how to resolve it without changing return type "Object" for method "returnArray".
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saloni jhanwar wrote:how to resolve it without changing return type "Object" for method "returnArray"

hint : typecasting
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot do without adding an explicit cast.
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, in your second code, I see two references with same name obj

This would also work:
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic