What are the key differences between OO in Smalltalk and Java?

前端 未结 7 1734
臣服心动
臣服心动 2021-01-30 13:31

What are the key differences between OO in Smalltalk and Java?

Please note that I am a Java programmer trying to expand his horizons by exploring Smalltalk. Currently I

7条回答
  •  不思量自难忘°
    2021-01-30 13:59

    One Smalltalk concept that doesn't exist in Java but has become increasingly popular in recent years is blocks. Blocks are a form of anonymous functions that include the context they were defined in. Importantly, blocks are also objects. Smalltalk actually lacked any kind of built-in if-statement or for-loop or anything like that, but managed to create the same effect just with message-passing and blocks.

    object isBig ifTrue: [self runIntoObject:object] 
                ifFalse: [self katamariBall absorbObject:object].
    
    1 to: 10 do: [:number | number print]
    

提交回复
热议问题