什么原因导致“此处不允许使用‘void’类型"?错误 [英] What causes "'void' type not allowed here" error

查看:36
本文介绍了什么原因导致“此处不允许使用‘void’类型"?错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译它时:

import java.awt.* ;

    class obj
    {
        public static void printPoint (Point p) 
        { 
            System.out.println ("(" + p.x + ", " + p.y + ")"); 
        }
        public static void main (String[]arg)
        {
            Point blank = new Point (3,4) ; 
            System.out.println (printPoint (blank)) ;
        }
    }

我收到此错误:

obj.java:12: 'void' type not allowed here
        System.out.println (printPoint (blank)) ; 
                                               ^
1 error

除了提问,我真的不知道如何开始提问:

I don't really know how to start asking about this other than to ask:

  • 这里出了什么问题?
  • 此错误消息是什么意思?

推荐答案

如果方法返回 void 则没有什么可打印,因此出现此错误消息.由于 printPoint 已经将数据打印到控制台,您应该直接调用它:

If a method returns void then there is nothing to print, hence this error message. Since printPoint already prints data to the console, you should just call it directly:

printPoint (blank); 

这篇关于什么原因导致“此处不允许使用‘void’类型"?错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆