什么是鸭打字? [英] What is duck typing?

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

问题描述

我在网上阅读随机主题时遇到了鸭子打字一词,但并没有完全理解.

I came across the term duck typing while reading random topics on software online and did not completely understand it.

什么是鸭子打字"?

推荐答案

动态语言中使用的术语没有强键入.

这个想法是,您不需要类型就可以调用对象上的现有方法-如果在对象上定义了方法,则可以调用它.

The idea is that you don't need a type in order to invoke an existing method on an object - if a method is defined on it, you can invoke it.

该名称来自短语如果它看起来像鸭子,而像鸭子一样嘎嘎叫,那是鸭子".

The name comes from the phrase "If it looks like a duck and quacks like a duck, it's a duck".

维基百科具有更多信息.

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

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