Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to transfer data in a object to another class

 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to pass method local object(object created in the method) to work as a parameter of a another class's constructor(same package)as a data?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejaka samarakoon wrote:how to pass method local object(object created in the method) to work as a parameter of a another class's constructor(same package)as a data?


How do you otherwise pass the references to methods? Even constructor is one such method.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejaka samarakoon wrote:how to pass method local object(object created in the method) to work as a parameter of a another class's constructor(same package)as a data?


Pass a reference. Or if immutability is a problem, pass a deep copy of the object
 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for the help.Can you give a solution
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot since it is a local variable and the main method takes String[] args.

I can think of an answer, but this does not seem anything to do with SCJP. Looks like Swing homework to me.
 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.Mr Bates.I'll post in the swing forum
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4682
333
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejaka samarakoon wrote:I'll post in the swing forum

No, please. Since this is not related to Swing/AWT, please continue the discussion here.

thejaka samarakoon wrote:How to get the rt object to the below code

As Deepak has already pointed out, you can't get rt object, as it resides in another local scope.
OK, if I spill the beans over here, you need to have a static variable in the class that holds a reference to that 'rt object'.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic