Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sequence point concept in java

Tags:

java

I am new to Java and have background of C.I am going through Khalid Moughal's book. On page 126 he gives an example as

   int i = 10;

   int k = ++i + --i; // ((++i) + (--i)).

This clearly violates the sequence point concept as of C,which says that you can't change the value of a variable more than once with in same sequence point. My question is does the same sequence point rule applies in java or not? It may be that he has taken this example just to explain the concept of prefix unary operator and it's side effect but such an example which clearly violates a very fundamental rule of the language is not expected in a book as renowned as Khalid Moughal.

So please confirm it.

Hope you people take it into proper spirit.

Thanks,

Mawia

like image 746
mawia Avatar asked Sep 15 '10 18:09

mawia


1 Answers

My question is does the same sequence point rule applies in java or not?

No, there are no sequence-points in Java. Order of evaluation (etc) is well defined in Java.

Also read this answer.

like image 122
Prasoon Saurav Avatar answered Oct 19 '22 22:10

Prasoon Saurav