惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

PCI Perspectives
PCI Perspectives
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
K
Kaspersky official blog
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
G
GRAHAM CLULEY
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
Intezer
D
Docker
月光博客
月光博客
L
Lohrmann on Cybersecurity
Latest news
Latest news
B
Blog
罗磊的独立博客
M
MIT News - Artificial intelligence
S
Securelist
Know Your Adversary
Know Your Adversary
Help Net Security
Help Net Security
Recorded Future
Recorded Future
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
T
Threatpost
H
Hacker News: Front Page
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
人人都是产品经理
人人都是产品经理
F
Fortinet All Blogs
博客园 - Franky
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
A
About on SuperTechFans
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tor Project blog
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Engineering at Meta
Engineering at Meta
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Security Blog
Microsoft Security Blog

博客园 - cindy_zl

SAP SD销售与分销模块 Agent认知框架ReAct&Plan RAG系统优化 RAG检索优化 RAG架构 SAA-C02-架构师助理级-英文版-Q1 scala-数组 navicat mysql创建存储过程报错 安装完kali出现中文乱码 Spark SQL是处理结构化的数据 SPARK SQL ERROR: Detected cartesian product for INNER join between logical plans报错解决方法 scala的lazy关键字 scala集合三大类(seq序列,set集,map映射)——map映射 scala集合三大类(seq序列,set集,map映射)——set集合 scala集合三大类(seq序列,set集,map映射)——list序列 scala元组及拉链操作 scala的map映射 scala数组 scala的基础数据类型&if条件表达式&for循环
scala方法和涵数的声明以及方法转换成涵数
cindy_zl · 2019-09-17 · via 博客园 - cindy_zl

scala方法和涵数的声明以及方法转换成涵数:

方法声明:

scala> def m1(x:Int, y:Int) : Int = x + y

m1: (x: Int, y: Int)Int

scala> m1(3,4)

res9: Int = 7

x + y为涵数体 

涵数声明:

scala> val f1 = (x: Int, y: Int) => x + y

f1: (Int, Int) => Int = <function2>

(Int, Int)参数类型

黄色是返回类型,后面的 <function2>表示两个参数的一个涵数,x + y为涵数体

scala> def m2(f:(Int,Int)=>Int) = f(3,4)

m2: (f: (Int, Int) => Int)Int 定入的一个方法m2并且方法的参数是一个涵数类型的参数,后面是方法的实现体

scala> val f1=(x:Int,y:Int) => x+y

f1: (Int, Int) => Int = <funtion2>定义一个有两个参数的涵数 f1,做为方法m2的参数传入方法体

scala> m2(f1) 方法里面传入涵数名调用(即scala可以将一个涵数当做参数进行传入)

res10: Int = 7

方法转换为一个涵数;

scala> def m1(x:Int,y:Int):Int=x+y         //定义一个两个参数为int类型且返回类型也是一个int的一个方法m1

m1: (x: Int, y: Int)Int

scala> val f1 = m1 _                        //将m1转换成涵数据并用 f1 接收  方法名+空格+下划线

f1: (Int, Int) => Int = <function2>

然后就可以调用 m2(f1)

scala> m2(f1)            传入转换过的涵数

res12: Int = 7

scala> m2(m1)           直接传入方法也没有报错是因为scala内部自动隐式转换成了涵数后当做m2方法的参数传入的,这有个隐式转换过程

res13: Int = 7