当前位置: 首页 > news >正文

免费制作网站和网页成都seo培

免费制作网站和网页,成都seo培,中国万网市值,自己制作的网页别人如何访问原文:https://gxnotes.com/article/83516.html 问题描述 给定以下用于在Scala中定义函数的结构,你可以解释什么是区别,它将会有什么影响? def foo {}与 def foo() {}更新 感谢您的快速回复。这些都很棒对我来说唯一的问题是&a…

原文:https://gxnotes.com/article/83516.html

问题描述

给定以下用于在Scala中定义函数的结构,你可以解释什么是区别,它将会有什么影响?

def foo = {}

def foo() = {}

更新

感谢您的快速回复。这些都很棒对我来说唯一的问题是:

如果省略括号,还有一种方法来传递函数吗?这是我得到的副本:

scala> def foo = {}
foo: Unitscala> def baz() = {}
baz: ()Unitscala> def test(arg: () => Unit) = { arg }
test: (arg: () => Unit)() => Unitscala> test(foo)
<console>:10: error: type mismatch;found   : Unitrequired: () => Unittest(foo)^scala> test(baz)
res1: () => Unit = <function0>

更新2012-09-14

这里有一些类似的问题我注意到:

  1. Difference between function with parentheses and without

  2. Scala methods with no arguments

最佳解决方案

如果在定义中包含括号,则可以在调用该方法时选择性地省略它们。如果您在定义中省略它们,则在调用该方法时不能使用它们。

scala> def foo() {}
foo: ()Unit

scala> def bar {}
bar: Unit

scala> foo

scala> bar()
<console>:12: error: Unit does not take parametersbar()^

此外,您可以执行类似于您的高阶功能的操作:

scala> def baz(f: () => Unit) {}
baz: (f: () => Unit)Unitscala> def bat(f: => Unit) {}
bat: (f: => Unit)Unitscala> baz(foo)    scala> baz(bar)
<console>:13: error: type mismatch;found   : Unitrequired: () => Unitbaz(bar)^
scala> bat(foo)scala> bat(bar)  // both ok

这里baz只能使用foo()而不是bar。这是什么用的,我不知道。但它确实表明,类型是不同的。

次佳解决方案

让我复制我的答案我张贴在a duplicated question:

可以使用或不使用括号()定义0级的Scala方法。这用于向用户发出该方法具有某种类型的side-effect(如打印输出或破坏数据),而不是以后可以实现为val

见Programming in Scala:

Such parameterless methods are quite common in Scala. By contrast, methods defined with empty parentheses, such as def height(): Int, are called empty-paren methods. The recommended convention is to use a parameterless method whenever there are no parameters and the method accesses mutable state only by reading fields of the containing object (in particular, it does not change mutable state).

This convention supports the uniform access principle […]

To summarize, it is encouraged style in Scala to define methods that take no parameters and have no side effects as parameterless methods, i.e., leaving off the empty parentheses. On the other hand, you should never define a method that has side-effects without parentheses, because then invocations of that method would look like a field selection.

参考文献

  • What is the difference between def foo = {} and def foo() = {} in Scala?

http://www.lbrq.cn/news/2599651.html

相关文章:

  • 建设雅马哈摩托车官网报价及图片网站关键词排名优化
  • 网站建设 软件开发网站搜索引擎优化情况怎么写
  • 自己做网站如何月入3k如何成为app推广代理
  • dw做网站实例项目推广网
  • 美武汉有什么网站建设公司策划营销
  • 开发公司 张庆网站建设排名优化
  • 电脑版和手机版网站怎么做企业网站建设需求分析
  • 长沙岳麓区做网站郴州网络推广公司排名
  • wordpress+爱情主题公园seo排名分析
  • 做网站需要先买域名吗seo有哪些经典的案例
  • seo整站优化公司100%能上热门的文案
  • 深圳网站制作公司深圳网站制作公司seo和sem的区别是什么?
  • 外包服务属于什么行业百度网站的优化方案
  • 东莞工商注册代办公司注册沈阳seo排名收费
  • 房山青岛网站建设河南怎样做网站推广
  • 奶茶电商网站建设长沙靠谱seo优化费用
  • 网站开发需要准备什么软件网站如何优化
  • 惠州网站建设价格2022年传销最新消息
  • 介绍一个电影的网站模板企业网页设计公司
  • 沭阳做网站的公司百度广告投放技巧
  • 做团购网站有什么难处百度搜索大数据查询
  • 许昌市网站开发自动优化app
  • 太原网站建设方案策划seo内部优化具体做什么
  • 帮人做网站要怎么赚钱如何宣传推广自己的产品
  • 网站建设销售好做扬州seo博客
  • 阿里云服务器 多个网站百度网站下拉排名
  • 360度网站模板网站优化招商
  • 医院哪个科室负责网站建设客户管理系统
  • 可以做机械设计接单的网站软文推广软文营销
  • 家庭宽带做私人网站厦门seo厦门起梦
  • Array容器学习
  • PCL统计点云Volume
  • 大屏项目展示
  • PostgreSQL面试题及详细答案120道(21-40)
  • 【1】WPF界面开发入门—— 图书馆程序:登录界面设计
  • 设计模式 - 组合模式:用树形结构处理对象之间的复杂关系