小编Geo*_*ton的帖子

Java中*=运算符的运算符优先级是什么?

这来自Java Generics和Collections中的Sets部分.下面的示例用于说明如何计算String的哈希码:

    int hash = 0;
    String str = "The red fox jumped over the fence";
    /** calculate String Hashcode **/
    for ( char ch: str.toCharArray()){
//      hash *= 31 + ch; this evaluates to 0 ????
        hash = hash * 31 + ch;
    }
    p("hash for " + str + " is " + hash);
Run Code Online (Sandbox Code Playgroud)

哈利为"红狐狸跳过篱笆"是1153233987386247098.这似乎是正确的.但是,如果我使用简写符号,*=,我的答案为0.

    int hash = 0;
    String str = "The red fox jumped over the fence";
    /** calculate String Hashcode **/
    for ( char ch: …
Run Code Online (Sandbox Code Playgroud)

java operator-precedence operator-keyword

1
推荐指数
1
解决办法
79
查看次数