方法是否重载了一种多态? [英] Is Method Overloading a Type of Polymorphism?

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

问题描述

我正在研究静态和动态多态,并得到以下链接:

I was studying about static and dynamic polymorphism and got these links:

http://guruzon.com/1/oop-concepts/polymorphism/what-is-polymorphism-example-tutorial -uml-diagram-notation

http://www.coderanch.com/t/379004/java/java/static-polymorphism-dynamic-polymorphism

http:/ /javarevisited.blogspot.in/2011/08/what-is-polymorphism-in-java-example.html

在所有这些链接中,它有有人说过载是多态的一个例子,然后我遇到了另外两个地方,据说重载无关wi多态性,链接是:

In all these links , It has been said that Overloading is an example of polymorphism , then I came across two more places where it has been said that overloading has nothing to do with polymorphism, the links are:

方法重载被认为是多态吗?

Head First Java第2版第7章(继承和多态)上一主题:重载方法的屏幕截图。

Head First Java 2nd Edition Chapter 7 (Inheritence and Polymorphism) Last topic: Overloading a method.

现在我无法弄清楚它是否是一种多态性,如果它不是OOP中有什么称为静态多态的话?

Now I am not able to figure out whether it is a kind of polymorphism or not and if it is not the is there anything called static polymorphism in OOPs ?

推荐答案

有时,方法重载确实被称为静态多态的一个例子。这种说法确实有点武断,但有可能做出有利的弱防御。

Sometimes, method overloading is indeed referred to as an example of "static polymorphism". This designation is somewhat arbitrary indeed, but it is possible to make a weak defense in its favor.

静态多态的概念确实存在,并不仅限于OOP 。当基于编译时类型信息实现多态行为时,多态性(以不同形式呈现相同行为的能力)可以是静态的。这种多态性最常见的例子是C ++模板:所有调用都是静态解析的,但模板的行为会根据其类型参数的静态类型而改变。

The concept of static polymorphism does exist, and it is not limited to OOP. Polymorphism (an ability to present the same behavior in different forms) can be static when polymorphic behavior is achieved based on compile-time type information. The most common example of such polymorphism is templates of C++: all calls are resolved statically, yet the behavior of a template is altered based on the static type of its type parameters.

重载可以被认为是基于对象的静态类型选择行为的原始形式。然而,这种重载的观点无助于理解概念,也使新手更难理解真实的(即动态的)多态性。这就是为什么术语静态多态性在Java书籍中并不常见。

Overloading could be thought of as a primitive form of choosing the behavior based on the static type of an object, too. However, this view of the overloading does not help understanding of the concept, and also makes it harder for the newcomers to understand the "real" (i.e. dynamic) polymorphism. That is why the term "static polymorphism" is not common in books on Java.

这篇关于方法是否重载了一种多态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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