Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return == in Java

Tags:

java

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;
}
like image 976
Whoppa Avatar asked Feb 04 '14 00:02

Whoppa


People also ask

What is return in Java?

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.

How do you return a value in Java?

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.

What does return 1 do in Java?

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.

Can you return doubles in Java?

The doubleValue() method of Java Double class returns the double value of this Double object.


2 Answers

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.

like image 93
yshavit Avatar answered Sep 18 '22 19:09

yshavit


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.

like image 29
Louis Wasserman Avatar answered Sep 17 '22 19:09

Louis Wasserman