Last active
June 24, 2019 04:08
-
-
Save joseoliv/0a2ffa39db758d6e3e422e464be65f0a to your computer and use it in GitHub Desktop.
prototypeCallOnly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package metaobjectTest | |
@doc{* | |
Annotation 'prototypeCallOnly' should be attached to a method. | |
It assures that the method is only called with a prototype | |
as receiver. This is a replacement for 'static' methods | |
of Java/C++/C#. An annotated method cannot access | |
non-shared fields and it should be final (either | |
declared with 'final' or the prototype is final). | |
*} | |
open | |
object PrototypeCallOnly | |
func run { | |
var PrototypeCallOnly p = PrototypeCallOnly(); | |
// error if uncommented | |
// p at: 10; | |
// p unary; | |
PrototypeCallOnly at: 10; | |
PrototypeCallOnly unary; | |
} | |
@prototypeCallOnly | |
final func at: Int n { value = n; } | |
@prototypeCallOnly | |
final func unary { value = 0; } | |
shared var Int value = 0; | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment