没有公共私有或受保护的变量是什么? [英] What are variables without public private or protected declared as?

查看:177
本文介绍了没有公共私有或受保护的变量是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不是:

private JButton theButton;

我这样做:

JButton theButton;

有什么区别?

谢谢

推荐答案

包。 他们对其他课程可见相同的包。

Package. They're visible to other classes in the same package.

FWIW,我通常在这些上使用我自己的无操作@Package注释,只是为了清楚地表明我知道我在做什么 - 我不只是忘了什么。虽然这是默认设置,但是高质量代码中的包访问可能比其他三种可能性更少 - 有一个很大的例外:

FWIW, I usually use my own no-op @Package annotation on these, just to make it clear that I know what I'm doing - that I didn't just forget something. Even though it's the default, package access is probably used less in high-quality code than any of the other three possibilities - with one big exception:

在某些样式的单元中测试时,希望能够访问通常是私有的方法或字段。提供访问权限的一种方法是将它们设置为包访问,并将单元测试类放在同一个包中(但通常放在不同的test目录树中)。一些开发人员认为这是不好的做法 - 一般来说,在测试中使用私有(或测试包)方法是不好的。

In some styles of unit testing, it's desirable to be able to get access to methods or fields that are normally private. One way to provide access is to set them to package access, and put the unit test class in the same package (but usually in a different "test" directory tree). Some developers think that this is bad practice - that in general, it's bad to use private (or package-for-testing) methods in tests.

这篇关于没有公共私有或受保护的变量是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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