I've been trying to find the meaning of returning == from a method. But I'm not sure what its called so I can't find any explanations online. If someone could point me to the correct resources or the name so I can search it that would be great. This is an example of what I don't understand.
public boolean isFull()
{
return length == entry.length;
}
In Java, return is a reserved keyword i.e, we can't use it as an identifier. It is used to exit from a method, with or without a value. Usage of return keyword as there exist two ways as listed below as follows: Case 1: Methods returning a value. Case 2: Methods not returning a value.
Returning a Value from a Method In Java, every method is declared with a return type such as int, float, double, string, etc. These return types required a return statement at the end of the method. A return keyword is used for returning the resulted value. The void return type doesn't require any return statement.
Your method has no return type, Provide a return type of int in your method. And return -1 means nothing in java, you are just returning a int value, thats it.
The doubleValue() method of Java Double class returns the double value of this Double object.
length == entry.length
is just a boolean expression. This is the same as:
public boolean isFull() {
boolean answer = (length == entry.length);
return answer;
}
The form you quoted is more succinct, and generally preferred.
If length
is equal to entry.length
, this returns true
. Otherwise, it returns false
.
This is just evaluating the expression length == entry.length
and returning the result of that expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With