Groups
Groups
Sign in
Groups
Groups
Scala中文社区
Conversations
About
Send feedback
Help
null, None, Nil, Nothing, Unit
64 views
Skip to first unread message
Yiding He
unread,
Nov 26, 2009, 9:54:32 PM
11/26/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scalacn
有些概念不是很理解,望指正!
null 好懂,就是不指向任何对象;
None 表示没有值,是 Option 的子类。Option 只有两个子类:Some 和 None。请问哪些地方用到了 Option?
Nil 就是空 List,Nil == List()
Nothing 号称是一切类的子类(?),而且是 final Trait,仅用于类型参数,如 List[Nothing]。Nothing 平常用不到吧?
--
致
礼!
yidi...@gmail.com
Xuefeng Wu
unread,
Nov 26, 2009, 11:19:02 PM
11/26/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sca...@googlegroups.com
你理解得很到位啊
Option在作为函数返回类型的时候特别有用。
当你的函数可能返回空或者有值时,用Option就表示了。
不然你的函数调用者总以为你返回的不会为空,在不知情的情况下没做空检查,就会出来NullPointException。
Nothing我还没用过。
2009/11/27 Yiding He
<
yidi...@gmail.com
>
--
Scala中文社区:
http://groups.google.com/group/scalacn
Yiding He
unread,
Nov 27, 2009, 12:03:42 AM
11/27/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sca...@googlegroups.com
谢谢!刚才忘了,还有一个 Unit,是不是 Scala 语法规定任何函数都要有返回类型,所以才无奈的用 Unit 表示无返回值的函数?
2009/11/27 Xuefeng Wu
<
ben...@gmail.com
>
--
致
礼!
yidi...@gmail.com
Xuefeng Wu
unread,
Nov 27, 2009, 12:12:25 AM
11/27/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sca...@googlegroups.com
应该是为了统一行吧,语法没有像Java那样规定如果没有返回值必须声明void,
你可以:
def foo {//doSomething}
不加等号,这样的函数就表示返回Unit.
2009/11/27 Yiding He
<
yidi...@gmail.com
>
--
Scala中文社区:
http://groups.google.com/group/scalacn
Reply all
Reply to author
Forward
0 new messages