0

我在记录我的代码时遇到了这个小问题。我试图记录许多类似于下面第一个示例的行,但它总是为该行上的每个变量提供完全相同的描述。

有没有办法记录每个变量,只使用一个文档(评论?),而不将我的变量声明行分成多行?

示例 1:

private boolean isDamage = true, isOverTime = false, interruptable = false, canBeDispelled     = false;

示例 2:(我如何尝试记录。)

/** This is a description. */
private boolean isDamage = true, isOverTime = false, interruptable = false, canBeDispelled = false;

下一个示例是我的变量声明区域当前的样子。如果我必须将我的多行声明分成多行,那么这将是一团糟。

/** The ID of the spell. */
private int id = -1;
/** The name of the spell. */
private String name = null;
private double damageMin = -1.0, damageMax = -1.0;
private double healMin = -1.0, healMax = -1.0;
private int effectTime = 1;
private double costMana = -1.0, costEnergy = -1.0, castTime = -1.0;
private boolean isDamage = true, isOverTime = false, interruptable = false, canBeDispelled = false;
/** Whether the spell is a buff or not. This only applies to buff and debuff spells. */
private boolean isBuff = false;
private int bonusStrength = 0, bonusDexterity = 0, bonusConstitution = 0, bonusIntelligence = 0, bonusWisdom = 0, bonusCharisma = 0;
private double bonusDamage = 0, bonusHealth = 0, bonusResource = 0; // bonusResource allows you to ass bonus energy or mana depending on the player's type.

感谢您的回复!

编辑:我发现并查看了这篇文章。这几乎就是我要问的,但那篇文章的答案不是我要找的。

4

1 回答 1

2

The names of the variables are very straightforward so unless you're javadoc documenting, there's no need to do so. You aren't doing this, so you can just use a general wording like

/* Defines spell behaviour */

When another dev reads your code he will have all the information he needs from this line and the variables their names. In fact, the comment might be not needed at all since it barely adds any value.

If you do want to use javadoc documentation you'll have to split it over multiple lines.

于 2013-09-27T14:07:58.220 回答