为什么我们将 String 数组作为参数传递给 main() 方法,为什么不是任何集合类型或包装类型或原始类型? [英] Why we Pass String array as argument to main() method, why not any collection type or wrapper type or primitive type?

查看:18
本文介绍了为什么我们将 String 数组作为参数传递给 main() 方法,为什么不是任何集合类型或包装类型或原始类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么必须在 main 方法中将字符串 arg[] 作为参数传递?为什么我们不能传递java中可用的任何其他数据类型?在java中的main方法中传递String arg[]的重要性是什么?

why is it mandatory to pass string arg[] as an argument in main method? why we cannot pass any other data type available in java? whats the importance of passing String arg[] in main method in java?

推荐答案

历史.这是自 C 时代以来的约定,甚至更早?Java 的大部分语法都来自 C.

History. This is a convention since the days of C, maybe even earlier? Java took most of its syntax from C.

此外,命令行参数是字符串,这就是数据类型的原因.Java 1 中不存在集合,因此它们不是一个选项.数组确实存在.

Also, command line arguments are Strings which is why that is the data type. Collections did not exist in Java 1 so they were not an option. Arrays did exist.

这篇关于为什么我们将 String 数组作为参数传递给 main() 方法,为什么不是任何集合类型或包装类型或原始类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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