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

时间:2013-07-17 19:49:54

标签: java javadoc

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

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

由于

1 个答案:

答案 0 :(得分: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.