写了类似下面的代码,老大说以后不准写这样的代码,小弟费解,求指教
代码情况(简写,意思已表达):
public static void main(String[] args) { Student stu = new Student(); //stu.xxx Student stu2 = new CodeStyle().getStudent(stu); } private Student getStudent(Student stu) { // xx ----- stu.setId(1); stu.setName("student"); return stu; }
即 目的是:调用getStudent()方法,在方法中对参数stu进行一些处理,最后得到一个Student对象返回
不过我的方式是在调用getStudent()方法前new一个对象,引用传递到getStudent()方法中对其进行处理
老大说这样写部署在分布式应用中会挂掉
他意思是 这样的代码应该在getStudent()方法里new一个Student对象,处理后在返回
类似上面的对象引用传递,处理,再返回会挂掉。
额 具体原因不知为何? 为何在那样的环境会挂掉?
求解, 谢谢了!(新手,分很少,谅解啊各位兄台)