老师好,为什么这2处不用new对象可以直接调用
来源:2-5 封装Web返回对象

____xyz
2021-09-05
输入正文
public class R extends HashMap<String,Object> { public R(){ put("code", HttpStatus.SC_OK); put("msg","success"); }
上面的put方法,还有下面的 return error方法,理论上好像应该是要new 一个R对象才能调用啊
public static R error(int code,String msg){ R r=new R(); r.put("code",code); r.put("msg",msg); return r; } public static R error(String msg){ return error(HttpStatus.SC_INTERNAL_SERVER_ERROR,msg); }
搜索
复制
写回答
1回答
-
静态方法不需要创建对象就能调用
052022-06-24
相似问题