Java do nothing

后端 未结 6 886
自闭症患者
自闭症患者 2020-12-29 02:16

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 effec

6条回答
  •  攒了一身酷
    2020-12-29 02:55

    I feel, there is no construct in Java identical to pass in Python. This is mostly because Java is a statically typed language where as Python is a dynamically typed language. More so when you are defining a method / function. In that context, the provided answers are valid / correct only for a method that returns void.

    For example for a Python function

    def function_returns_void:
        pass
    

    you can have a Java method

    public void function_returns_void(){}
    

    or

    public void function_returns_void(){;}
    

    but when a method is supposed to return a value, while pass may still work in Python, one will stuck with compilation problem when not returning a value.

提交回复
热议问题