在java中的序列点概念 [英] sequence point concept in java

查看:91
本文介绍了在java中的序列点概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的新手并拥有C.的背景。我正在阅读Khalid Moughal的书。
第126页他给出了一个例子

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)).

这显然违反了C语言中的序列点概念,它表示您无法更改值变量不止一次与相同的序列点。
我的问题是,相同的序列点规则是否适用于java?
可能他已经用这个例子来解释前缀一元运算符的概念及其副作用但是这样一个明显违反语言非常基本规则的例子并不像Khalid那样出名。 Moughal。

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.

所以请确认一下。

希望你们让人们认真对待。

Hope you people take it into proper spirit.

谢谢,

Mawia

推荐答案


我的问题是,相同的序列点规则是否适用于java?

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

否,Java中没有序列点。评估顺序(等)在Java中定义良好。

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

同时阅读这个答案。

这篇关于在java中的序列点概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆