本文介绍了什么是Java重载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白Java中的重载。与多态性有关系吗?对我来说这似乎很抽象。
我来自Javascript语言?这是否适用于Javascript?

I don't understand the overloading in Java. Is there a relation with polymorphism ? It seems very abstract for me.I come more from Javascript language ? Would this apply so in Javascript ?

推荐答案

重载意味着可以使用多个签名定义相同的方法名称—正式参数列表(及其类型)。

Overloading means that the same method name can be defined with more than one signature — the list of formal parameters (and their types).

重载意味着不同语言的不同内容。 Java是强类型的(事实上有些人可能会说凶狠地打字)。它只是意味着可以有一个函数的不同版本,编译器可以通过查看函数(方法)调用中的参数类型来判断哪一个函数。

Overloading means different things in different languages. Java is strongly typed (some might say "fiercely typed" in fact). It just means that there can be different versions of a function and the compiler can tell which one is intended by looking at the types of parameters in a call to the function (method).

JavaScript不是那样的;函数的形式参数只是在函数体中按名称引用,但是没有什么特别的,它们可以用任何参数和任意数量的函数调用任何函数。

JavaScript is not like that; the formal parameters to a function are just references by name in the function body, but otherwise there's nothing special about them and any function can be called with any arguments and any number of them.

有些语言使用重载作为运行时概念。在Erlang中,从函数的几个替代版本中挑选时,并不重要的 types 参数;它是

Some languages use "overloading" as a runtime concept. In Erlang, it's not the types of arguments that matter when picking from several alternative versions of a function; it's the values.

编辑— @MarkoTopolnik指出问题不在于类型系统的强度(或凶猛:-),而在于它的静态程度。 Java坚持要在几乎所有地方显式声明类型,而JavaScript(除了一些新的类型数组结构)不会。

edit — @MarkoTopolnik points out that the issue isn't so much about the "strength" (or "ferocity" :-) of the type system, but about how static it is. Java insists on types being explicitly declared pretty much everywhere, while JavaScript (excepting some of the new typed array constructs) doesn't.

这篇关于什么是Java重载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 16:57