java中的这种语法写法,语法居然没问题,你们见过吗? this.url = (this.var = null);这句话我没明白什么意思?请教高手?有谁知道这句话什么意思,能详细解释说明下吗?public class Test
{
  protected String url;
  private String var;
  private int scope;  private void init() {
    this.url = (this.var = null);
    this.scope = 1;
  }

解决方案 »

  1.   

    public class Test
    {
      protected String url;
      private String var;
      private int scope;
     
      private void init() {
        this.url = (this.var = null);//先计算this.var=null,值为空,再计算this.url=null;,所以肯定没问题呀,()的优先级高吗!
        this.scope = 1;
      }
      

  2.   

    为什么不写成  this.url =  this.var = null;
      

  3.   

    这是什么写法?public class Test
    {
      protected String url;
      private String var;
      private int scope;
     
      private void init() {
        this.url = (this.var = null);
        this.scope = 1;
      } 

      private void init() {
    this.var = null
        this.url =this.var;
        this.scope = 1;
      } 
    这两种是等价的。
      

  4.   

     this.url =  this.var = null; 不也等价你的两种?这是什么写法?public class Test
    {
      protected String url;
      private String var;
      private int scope;
     
      private void init() {
        this.url = (this.var = null);
        this.scope = 1;
      } 

      private void init() {
    this.var = null
        this.url =this.var;
        this.scope = 1;
      } 
    这两种是等价的。
      

  5.   

     
    int len = 0;
    FileInputStream fis = null;
    byte [] buf = new byte[1024];
    while((len = fis.read(buf))!=-1){
    //跟这个差不多的意思
    }//下面这种写法也是没问题的
    double a = .5;
    double b = 5.;
      
      

  6.   

    这是什么写法?public class Test
    {
      protected String url;
      private String var;
      private int scope;
     
      private void init() {
        this.url = (this.var = null);
        this.scope = 1;
      } 

      private void init() {
    this.var = null
        this.url =this.var;
        this.scope = 1;
      } 
    这两种是等价的。

    应该是为了防止读代码的时候发生歧义吧。
      

  7.   

    有什么可奇怪的,C 语言时代就开始这么写了,Java 一样的搬过来了:try (BufferedReader br = Files.newBufferedReader(path)) {
    String line;
    while ((line = br.readLine()) != null) {
    //
    }
    }
      

  8.   

    这是什么写法?public class Test
    {
      protected String url;
      private String var;
      private int scope;
     
      private void init() {
        this.url = (this.var = null);
        this.scope = 1;
      } 

      private void init() {
    this.var = null
        this.url =this.var;
        this.scope = 1;
      } 
    这两种是等价的。

    应该是为了防止读代码的时候发生歧义吧。
    java不能这样写,js可以写成a=b=1
      

  9.   

    这是什么写法?public class Test
    {
      protected String url;
      private String var;
      private int scope;
     
      private void init() {
        this.url = (this.var = null);
        this.scope = 1;
      } 

      private void init() {
    this.var = null
        this.url =this.var;
        this.scope = 1;
      } 
    这两种是等价的。

    应该是为了防止读代码的时候发生歧义吧。
    java不能这样写,js可以写成a=b=1
    为啥不能这样写?你写的报错了?
      

  10.   

    这是什么写法?public class Test
    {
      protected String url;
      private String var;
      private int scope;
     
      private void init() {
        this.url = (this.var = null);
        this.scope = 1;
      } 

      private void init() {
    this.var = null
        this.url =this.var;
        this.scope = 1;
      } 
    这两种是等价的。

    应该是为了防止读代码的时候发生歧义吧。
    java不能这样写,js可以写成a=b=1
    为啥不能这样写?你写的报错了?
    同学看清楚 我说的是js可以写成a=b=1 
     var a=b=1;
        console.log(a);
        console.log(b);
    java那个我收回 确实可以
    int b;
         int a=(b=1);//a=b=1
         System.out.println(a);
    但是很少人会这么去用,你那里需要这样赋值的点呢?请给我一个场景