java - 错误 "Void type not allowed here."请帮助我

标签 java

它一直给我一个错误“此处不允许使用 Void 类型”。

public class BugTester {
    public static void main(String[] args) {
        Bug bugsy =  new Bug(10); 
        bugsy.move();  //now the position is 11
        bugsy.turn();      
        bugsy.move();  //now the position is 10
        bugsy.move();
        bugsy.move();
        bugsy.move();

        // Error message highlights this.
        System.out.println("The bug position is at "+bugsy.move());
    }
}

最佳答案

Bug的move()方法没有返回值。这是一个无效的方法。您不能将任何内容连接到字符串。

也许还有另一种 Bug 方法,您想打印 getPosition() 之类的值?

关于java - 错误 "Void type not allowed here."请帮助我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4047718/

相关文章:

java - 如果没有用Gson初始化如何不写float(GsonBuilder())

Java EE 请求范围和异步

Java正则表达式匹配括号外

java - 如何在 Spring Boot 2 中检索应用程序上下文

java - 某处是否有 java 字符串文字的 jflex 规范?

java - C# 类似属性 get/set,而不是私有(private)变量和单独的 getter/setter 方法

Java Class.cast() 与强制转换运算符

java - 远程运行 MapReduce

java.lang.NoSuchFieldException : cacheList

java - 如何告诉 JRE 使用多个 CPU 节点