0

I want to create an object within a class, sending reference as a parameter to a function. Ho do I do that? It is very important to me.

public class TestClass {

    private static Object someObject;


    public static void main(String[] args) {

        method(someObject);
    }

    private static void method(Object a)
    {
        a=new Object();
    }
}
Walter White
  • 51
  • 1
  • 1
  • 9
  • You cannot do it that way. You can do `Object someObject = method()` where it is `Object method() { return new Object; }`; – KevinO Apr 18 '16 at 19:10
  • What is your usecase? Maybe you have to make a small redesign. For the most problems there is already a design pattern. Refer [www.oodesign.com](http://www.oodesign.com) – Simon Schüpbach Apr 18 '16 at 19:13
  • I have to make a gui design. But it isnt nice to do for each button, and label 5 things(so the method do this for both button and label). Like creating object, settingname, setting visibility. So I created a method to do this. But I defined the reference to the object outside my method. Because I need later to change the things like name of button or label etc. Do you follow me guys? – Walter White Apr 18 '16 at 19:19

0 Answers0