java中不允许使用Void类型 [英] Void type not allowed in java

查看:243
本文介绍了java中不允许使用Void类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于java的问题,请告诉我原因

  class  M {
public static void main( String [] args){
M m = new M();
m.a();
System。 out .println(m.a());
}
void a(){
系统。 out 。 println( Ok);
}
}

回答成为
此处不允许使用Void类型

解决方案

你传递 ma()作为 println 函数的参数,但 a()的返回类型是 void ,你不能把它作为参数传递。



你真的不需要包裹 ma() println 里面,因为当你调用 a 方法时,它已经打印了一些东西。

i hav e one question regarding the java please tell me the reason

class M{
public static void main(String[] args) {
M m=new M();
m.a();
System.out.println(m.a());
}
void a(){
System.out.println("Ok");
}
}

answer become 
Void type not allowed here"

解决方案

You pass m.a() as argument to the println function, but the return type of a() is void, and you cannot pass that as argument.

You really don't need to wrap m.a() inside println, because when you call the a method, it already prints something.


这篇关于java中不允许使用Void类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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