Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java do nothing

Tags:

java

python

What is the equivalent to Python's pass in Java? I realize that I could use continue or not complete the body of a statement to achieve that effect, but I like having a pass statement.

like image 766
goodcow Avatar asked Mar 19 '14 00:03

goodcow


People also ask

Is there a do nothing in Java?

There is no (strict) equivalent since in java you have to specify the return type for the method in its declaration which is then checked against a computed type of the following the return statement.

How do you make an else do nothing in Java?

Simply remove else { return false } . Notice that there is a big diference between else {} and else {return false} In the second case the function will stop in the else scenario.

What is pass in Java?

Object variables in Java always point to the real object in the memory heap. A mutable object's value can be changed when it is passed to a method. An immutable object's value cannot be changed, even if it is passed a new value. “Passing by value” refers to passing a copy of the value.


2 Answers

Just use a semi-colon ;, it has the same effect.

like image 79
James Avatar answered Sep 21 '22 23:09

James


If you want something noticeable, you can use

assert true; 

This will allow you to have something that a reader can recognize or that can be searched for.

like image 24
sabbahillel Avatar answered Sep 22 '22 23:09

sabbahillel