java - C++ 到 Java 中的全局变量

标签 java c++ global-variables

如何在 Java 中编写所有这些 C++ 全局变量?

  //Global variables
  int charClass;
  char lexeme [100];
  char nextChar;
  int lexLen;
  int token;
  int nextToken;
  extern string word("Apple");

最佳答案

类中的公共(public)静态变量怎么样?

public class Globals {
    public static int charClass;
    public static char[] lexeme = new char[100];
    public static char nextChar;
    public static int lexLen;
    public static int token;
    public static int nextToken;
    public static String word = "Apple";
}

有一些差异,但主要思想是相似的(至少对于原语而言)。

关于java - C++ 到 Java 中的全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10469593/

相关文章:

c++ - 为什么在我嵌入 perl 后 MIcroQuill Smartheap 会抛出 "mem_bad_pointer"错误?

memory - 更糟糕的罪过 : side effects or passing massive objects?

c++ - 先前在 cuda c++ 中定义的外部全局设备变量

java - 收到致命警报 : protocol_version build failure Gradle/Maven

java.lang.IllegalArgumentException : ResourceLoader must not be null in Spring

java - 标志或每个标志可能值的单独方法?

java - 是否指定 @Transactional rollbackFor 还包括 RuntimeException

c++ - 指针的大小是多少?它具体取决于什么?

c++ - 具有默认值的单参数构造函数是否可以进行隐式类型转换

python - 动态分配变量