java中不允许使用Void类型 [英] Void type not allowed in java
本文介绍了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 passm.a()
as argument to theprintln
function, but the return type ofa()
isvoid
, and you cannot pass that as argument.
You really don't need to wrapm.a()
insideprintln
, because when you call thea
method, it already prints something.
这篇关于java中不允许使用Void类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文