Java out.println()这怎么可能? [英] Java out.println() how is this possible?

查看:83
本文介绍了Java out.println()这怎么可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过一些代码,例如:

I've seen some code such as:

out.println("print something");

我尝试了import java.lang.System;

但是它不起作用.您如何使用out.println()?

but it's not working. How do you use out.println() ?

推荐答案

静态导入可以解决问题:

static imports do the trick:

import static java.lang.System.out;

或使用

import static java.lang.System.*;


@Steve C的附录:请注意,@ sfussenegger在对我的答案的评论中说了这一点.


Addendum by @Steve C: note that @sfussenegger said this in a comment on my Answer.

使用System.out的静态导入不仅仅适用于简单的一次性代码."

因此,请不要以为他(或我)认为此解决方案是良好实践.

So please don't imagine that he (or I) think that this solution is Good Practice.

这篇关于Java out.println()这怎么可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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