1

为什么默认构造函数总是出现在 javadoc 文档中,即使它不存在于代码中?

一种可能的补救措施是显式编写默认构造函数,即使我不需要它,只需向它添加注释“仅供内部使用”或类似的东西......

谢谢

4

1 回答 1

2

根据http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

The compiler automatically provides a no-argument, default constructor for any class without constructors

这意味着,默认构造函数将在编译时隐式添加。当时,当它获取 javadoc 时,它已经被添加了。这在此处指定http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#defaultconstructors

Section 8.8.7 of the Java Language Specification, Second Edition describes a default constructor: If a class contains no constructor declarations, then a default constructor that takes no parameters is automatically provided. It invokes the superclass constructor with no arguments. The constructor has the same access as its class.
The Javadoc tool generates documentation for default constructors. When it documents such a constructor, Javadoc leaves its description blank, because a default constructor can have no doc comment. 
于 2013-07-17T19:56:00.937 回答