Soundsgoood
Soundsgoood

Reputation: 315

What do you write for javadoc for a method that does nothing?

I have a method in my class that does nothing.

public class SpecialCheckingAccount extends BankAccount
{
    public void deductWithdrawalFees()
    {}
}

That method is only there because BankAccount has it as an abstract method. BankAccount calls deductWithdrawalFees() every time someone makes a withdrawal. It's supposed to deduct a withdrawal fee.

The SpecialCheckingAccount class represents a special checking account that doesn't have a withdrawal fee.

I was under the impression every method should have a javadoc. How do you javadoc a method like this?

EDIT: deductWithdrawalFees() in the BankAccount class (the abstract superclass) has Javadoc ("Deduct the fees associated with making a deposit from the balance") but I feel that it doesn't quite apply to an empty implementation, where nothing is technically deducted, and the fee is nonexistent. Thus I don't think inheriting the javadoc would really be an answer to this question.

Upvotes: 2

Views: 422

Answers (3)

victor
victor

Reputation: 812

I would take this and expand on it, explaining why the method is there with an implementation that does nothing: "The SpecialCheckingAccount class represents a special checking account that doesn't have a withdrawal fee."

Suggestion from @Andreas: A good Java Runtime Library example of something like this is the javadoc of AbstractList.set(int index, E element), which repeats the javadoc of the interface and adds: This implementation always throws an UnsupportedOperationException. --- To use the same phrasing, your javadoc could say: This implementation does nothing, since a special checking account doesn't have a withdrawal fee.

Upvotes: 5

Steve
Steve

Reputation: 151

You could have the deduction be a value of zero to have it "function". Then specify in the doc the purpose of the special checking account is to have no withdrawal fees.

Upvotes: 0

Axel
Axel

Reputation: 14159

Why write a Javadoc at all? BankAccount.deductWithdrawalFees() should have one, and that should be all that is needed. I would however document the empty block like this:

public class SpecialCheckingAccount extends BankAccount
{
    @Override
    public void deductWithdrawalFees()
    {
        // nop: SpecialCheckingAccount has no withdrawal fee.
    }
}

You should also add the @Overrideannotation.

Upvotes: 1

Related Questions