当前位置:网站首页>Nine ways to define methods in scala- Nine ways to define a method in Scala?
Nine ways to define methods in scala- Nine ways to define a method in Scala?
2022-07-03 15:57:00 【fyin1314】
problem :
So I've been trying to puzzle through the various ways you can define stuff in Scala, complicated by my lack of understanding of the way {} blocks are treated: therefore , I have been trying to solve your problem in Scala Method of defining content in , And because I am {} The processing of blocks is complicated due to lack of understanding :
object NewMain extends Thing{ def f1 = 10 def f2 {10} def f3 = {10} def f4() = 10 def f5() {10} def f6() = {10} def f7 = () => 10 def f8 = () => {10} def f9 = {() => {10}} def main(args: Array[String]){ println(f1) // 10 println(f2) // () println(f3) // 10 println(f4) // 10 println(f4()) // 10 println(f5) // () println(f5()) // () println(f6) // 10 println(f6()) // 10 println(f7) // <function0> println(f7()) // 10 println(f8) // <function0> println(f8()) // 10 println(f9) // <function0> println(f9()) // 10 }}Presumably some of these are equivalent, some of these are syntactic sugar for others, and some are things I should not use, but I can't for the life of me figure it out. Presumably , Some of them are equivalent , Some of them are other people's grammatical sugar , Some things I shouldn't use , But I can't figure it out for my life .My specific questions are: My specific question is :
How is it that
println(f2)andprintln(f5())givesunit?println(f2)andprintln(f5())giveunit?Isn't the last item in the block10? No10The last item of the block ?How is it different fromprintln(f3()), which gives10? It is associated withprintln(f3())What's the difference , It gives10?If
println(f5)givesunit, shouldn'tprintln(f5())be invalid, sinceunitis not a function? Ifprintln(f5)giveunit, Should not beprintln(f5())Invalid , becauseunitNot a function ?The same applies toprintln(f6)andprintln(f6())This also applies toprintln(f6)andprintln(f6())Of all the ones which print 10:
f1,f3,f4,f4(),f6,f6(),f7(),f8(),f9(), is there any functional difference between them (in terms of what it does) or usage differences (in terms of when I should use which)? Print in all 10:f1,f3,f4,f4(),f6,f6(),f7(),f8(),f9(), Are there any functional differences between them ( In terms of its function ) ) Or use difference ( In terms of when to use )?Or are they all equivalent? Or they are all the same ?
Solution :
Reference resources : https://stackoom.com/en/question/YqCX边栏推荐
- About text selection in web pages and counting the length of selected text
- Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
- Nifi from introduction to practice (nanny level tutorial) - flow
- 互斥对象与临界区的区别
- Microservice - declarative interface call openfeign
- How to use annotations such as @notnull to verify and handle global exceptions
- pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
- QT use qzxing to generate QR code
- 一些事情的反思
- App mobile terminal test [3] ADB command
猜你喜欢

Nifi from introduction to practice (nanny level tutorial) - flow

From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing

Subclass hides the function with the same name of the parent class

Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!

How idea starts run dashboard

String functions that you need to know

Detailed pointer advanced 2

关于网页中的文本选择以及统计选中文本长度

Seckill system 2 redis solves the problem of distributed session

uploads-labs靶场(附源码分析)(更新中)
随机推荐
About text selection in web pages and counting the length of selected text
How idea starts run dashboard
Halcon and WinForm study section 2
"Remake Apple product UI with Android" (3) - elegant statistical chart
The wonderful use of do{}while()
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
[list to map] collectors Tomap syntax sharing (case practice)
Reflection on some things
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
自定义注解
详解指针进阶2
The difference between mutually exclusive objects and critical areas
阿飞的期望
How are integer and floating-point types stored in memory
Microservices Seata distributed transactions
Visual upper system design and development (Halcon WinForm) -2 Global variable design
How to use annotations such as @notnull to verify and handle global exceptions
WinDbg分析dump文件
Second kill system 3 - list of items and item details