java - PrintStream 类型中的方法 println(boolean) 不适用于参数 (void)

标签 java

当我尝试执行以下代码时出现错误:

package Abc;

public class Class3 {

    public void another() {
        System.out.println("Hello World");
    }

    public static void main(String[] args) {
        Class3 obj1 = new Class3();
        System.out.println(obj1.another());
    }

}

错误是:

The method println(boolean) in the type PrintStream is not applicable for the arguments (void)

最佳答案

您的 another() 函数返回类型为“void”,这实际上表示它被定义为不返回任何内容。

package Abc;

public class Class3 {
    public void another() {
       System.out.println("Hello World");
    }

   public static void main(String[] args) {
    Class3 obj1 = new Class3();
    obj1.another();
    }

}

关于java - PrintStream 类型中的方法 println(boolean) 不适用于参数 (void),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43436261/

相关文章:

java - PriorityQueue 是 FIFO 队列吗?

java - Php 编码 - Java 解码(URL 部分)

java - 在另一个中编译类时出现编译错误

java - 在 ORACLE 作为数据库的情况下,在 SPRING-Hibernate 应用程序中使用 BLOB 给出 "java.lang.ClassNotFoundException: oracle.sql.BLOB"!

java - 清除 Swing GUI 中的 ImageIcon 和相关操作

java - 向 Heroku 启动 Dropwizard 项目失败

java - 验证 int 值

java - 零是 Android 中 ScheduledThreadPoolExecutor 的有效 corePoolSize 吗?

java - Java/Android 中的 Modbus TCP

java - 使用Aspectj查找实现某个接口(interface)的类列表