在哪个版本的Java中,将false赋值给整数变成无效?

huangapple go评论82阅读模式
英文:

In what version of Java did assigning false to an integer become invalid?

问题

我有以下来自一个看起来是 Java 1.1 库的遗留代码:

int colon_index = false;

for(int i = 0; i < params_split.length; ++i) {
    int colon_index = params_split[i].indexOf(":");
    if (colon_index > 0) {
        // ...
    }
}

它似乎将 false 赋值给了一个类型为 int 的变量。这是反编译的代码,因此 IntelliJ 反编译器也有可能出错。

我已经查阅了旧版本的发布说明,但还没有找到这个更改。

假设在 Java 的某个历史版本中这是正确的,在哪个版本的 Java 中停止支持这种语法?

英文:

I have the following legacy code from what looks to be a Java 1.1 library:

int colon_index = false;

for(int i = 0; i < params_split.length; ++i) {
    int colon_index = params_split[i].indexOf(":");
    if (colon_index > 0) {
        // ...
    }
}

It appears to be assigning false to a variable of type int. This is decompiled code, so it's also possible the IntelliJ decompiler has made a mistake.

I've checked release notes for old versions, but haven't been able to spot this change yet.

Assuming this was correct at some point in Java's history, in what version of Java did this syntax stop being valid?

答案1

得分: 0

你不能相信反编译的代码。最初,它应该是int colon_index = 0

查看这个答案以获取更多详情。

英文:

You can't trust decompiled code. Originally, it would've been int colon_index = 0

Check out this answer for more details.

huangapple
  • 本文由 发表于 2020年9月10日 18:10:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63827409.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定