返回java中的main类型 [英] return type of main in java

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

问题描述

我想知道为什么只有java中main方法的void返回类型。

I like to know why only void return type for main method in java.

public static void main(String [] args)

为什么除了main方法之外没有其他的返回类型。

Why there is no other return types other than void for main method.

谢谢

推荐答案

简短的回答是:因为那是语言规范说。

The short answer is: Because that's what the language specification says.

在当今常用的操作系统(Windows和Unix系列)中,进程中唯一的返回值是退出状态,这是一个小数字(通常是8位)。可以使用 System.exit(int) 方法:

In today's commonly used operating systems (Windows and Unix families), the only "return value" from a process is an exit status, which is a small number (usually 8-bit). This value can be returned from a Java program using the System.exit(int) method:


public static void exit(int status)

终止当前运行的Java虚拟机。该参数用作状态代码;按照惯例,非零状态代码表示异常终止。

Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

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

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