gpt4 book ai didi

java - 当我用 static 声明变量时,我得到了非法的表达式开始?

转载 作者:行者123 更新时间:2023-12-02 06:19:20 24 4
gpt4 key购买 nike

static int basketballPlayer; 
static int activebasketballPlayers;
static int legendbasketballPlayers;

表达式的非法开始

最佳答案

在 Java 中,static 修饰符适用于字段方法。请参阅Understanding Class Members其中简要讨论了修饰符的使用。

class Foo {
static int foo; // okay - static applied to field
}

但是static不能与Java中的局部变量一起使用

class Bar {
void x () {
static int bar; // fail - static cannot be applied to local variables
}
}

上面的结果会导致熟悉的编译器错误:

error: illegal start of expression
static int bar;

关于java - 当我用 static 声明变量时,我得到了非法的表达式开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21149699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com