Is there a difference between return (val) and return val ?

    1 answer 1

    There is no difference. Something is indicated in brackets usually to improve readability (in expressions, the priority of operations can be placed this way).


    Brackets work the same way: for example, such expressions will be completely similar in terms of work, but the first one is better read:

     (variable == null) ? this.pullVariable(variable) : this.pushVariable(variable); variable == null ? this.pullVariable(variable) : this.pushVariable(variable); 

    Also in Java, type brackets are used for conversion. For example:

     Object object = (Object) variable; 

    The same transformation can be used with the return :

     return (Object) variable; 
    • or to raise the priority) - diofloyk
    • one
      @crowlie, I added. - Rostislav Dugin
    • It can be read better in the first case, everywhere its rules. But the first case seems to hint at the lack of knowledge of the priorities of the operation as a consequence of excessive brackets. I apologize for such a comment, but could not not write. The answer is useful beyond doubt) - diofloyk