是否可以在不使用类名的情况下调用另一个类的静态方法? [英] Can I call a static method of another class without using the class name?

查看:73
本文介绍了是否可以在不使用类名的情况下调用另一个类的静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不使用类名的情况下(在同一程序包中)调用另一个类的 static 方法?有类似的问题,但所有答案都使用类名。

Can I call a static method of another class without using the class name (in the same package)? There are similar questions but all answers there use class names.

推荐答案

但是,您需要导入 具体 导入静态。就像

Yes. But, you would need to import it. Specifically, import static. Like,

import static com.package.OtherClass.someMethod;

然后您可以调用 someMethod(String)例如

someMethod("Like that");

这篇关于是否可以在不使用类名的情况下调用另一个类的静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆