静态方法调用 [英] Static method invocation

查看:127
本文介绍了静态方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在不提及Java中的类名的情况下调用静态方法吗?

Can we call a static method without mentioning the class name in Java?

推荐答案

是的,你可以。查看静态导入。您必须在 import 语句中提及类名,但之后您不必以。来自链接文章:

Yes you can. Check out static imports. You have to mention the class name in the import statement, but after that you don't have to.e.g. from the linked article:

import static java.lang.Math.abs;
import static java.lang.Math.max;

int xDist = abs(destination.getX() - x);
int yDist = abs(destination.getY() - y);
return max(xDist, yDist);

在Java 5中引入。

Introduced in Java 5.

这篇关于静态方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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