Reputation: 55
I believe that I am having trouble understanding how to give a signature of a method in Java. For example, if my code was:
public void addOn(Fraction other) {
number = other.denominator * number + other.numerator * denominator;
denominator = denominator * other.denominator;
and I had to give the signature of the method addOn();
Would the signature for this method simply be addOn(Fraction);?
Upvotes: 4
Views: 2113
Reputation: 1598
I believe, you should refer this article.
It clearly states that a method signature only contains:
All other parts like exceptions, return types, annotations are part of method declaration not signature.
Along with these syntactical things, semantics should also be considered while choosing a method name.
I would recommend you to go through java coding guidelines.
Upvotes: 0
Reputation: 407
In Java the method signature contains the name of the method and the data type of the arguments only and nothing else.
For eg in the method posted by you above:
public void addOn(Fraction other) {
}
the signature will be addOn(Fraction ).
This is one of the difference between C++ and java in C++ signature also contains return type but in java return type is not part of method signature. So in case of C++ method signature of above method will be void addOn(Fraction);
Upvotes: 3
Reputation: 1975
If you want to pass Fraction
as parameter to the class. First you need to create reference of Fraction
like
Fraction ref =new Fraction();//Assuming Fraction class has default constructor
Then you can pass it as;
addOn(ref);//Ref of Fraction class as parameter
Upvotes: 1
Reputation: 140467
That really depends on the level of "accuracy" that you need.
When you informally talk to you coworker, then the "signature" would probably contain all information that a human being might find interesting:
Whereas, when you come from a compiler-constructor or maybe JVM compiler point of view, the answer is different; in that case, only items 2, and 3 do matter; anything else is not part of the signature.
Upvotes: 4