Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Last active June 24, 2019 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseoliv/0a2ffa39db758d6e3e422e464be65f0a to your computer and use it in GitHub Desktop.
Save joseoliv/0a2ffa39db758d6e3e422e464be65f0a to your computer and use it in GitHub Desktop.
prototypeCallOnly
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