fork(1) download
  1. class Foo {
  2. private final boo;
  3.  
  4. Foo(boo) { this.boo = boo }
  5. def bar() { "original $boo" }
  6. }
  7.  
  8. class FooCategory {
  9. def static bar(Foo self) { "categorical ${self.boo}" }
  10. }
  11.  
  12. def f = new Foo('hello')
  13.  
  14. assert f.bar() == 'original hello'
  15.  
  16. use(FooCategory) { assert f.bar() == 'categorical hello' }
  17.  
  18. class Baz {
  19. def quux(boo) { new Foo(boo).bar() }
  20. }
  21.  
  22. use(FooCategory) { assert new Baz().quux('no') == 'original no' } // fails as quux returns 'categorical no' even though Foo.bar is not called in this lexical scope!
Success #stdin #stdout 1.41s 218496KB
stdin
Standard input is empty
stdout
Standard output is empty