简体   繁体   English

Java中的空花括号/括号是什么意思?

[英]What do empty curly brackets/braces mean in Java?

Here is the whole source code: 这是完整的源代码:

http://zerioh.tripod.com/ressources/sockets.html http://zerioh.tripod.com/ressources/sockets.html

Here is the code I want to highlight: 这是我要强调的代码:

Provider(){}

What does this line means? 这条线意味着什么? Thanks. 谢谢。

It means that there's nothing to execute in this Constructor. 这意味着在此构造函数中无需执行任何操作。 Usually Java provides this by default so writing down Provider(){} is not necessary. 通常Java默认提供此功能,因此不必写下Provider(){}。

The main difference between this one and the one that is provided by the compiler by default is that the access is restricted since it's not public. 默认情况下,此编译器与编译器之间的主要区别在于访问受限制,因为它不是公共的。

它是一个具有默认辅助功能的构造函数。

The no-arg constructor is simply being defined instead of being undeclared. 简单地定义no-arg构造函数而不是未声明的构造函数。 However, since the access level modifier "public" was left out, this means the no-arg constructor is defined using the default package. 但是,由于省略了访问级别修饰符“public”,这意味着使用默认包定义了无参数构造函数。

This means that any classes outside the package will not be able to instantiate it. 这意味着包外的任何类都无法实例化它。 Only classes within the package can instantiate the Provider class. 只有包中的类可以实例化Provider类。

It is default constructor which does nothing. 它是默认构造函数 ,什么都不做。

An object of this class can be created withing the package. 可以使用包创建此类的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM