Home | Back | Contents | Next |
Note: If you print a 'this' type reference you'll see what it refers to: BeanShell 1.3 - by Pat Niemeyer ([email protected]) bsh % print( this ); 'this' reference (XThis) to Bsh object: global bsh % foo() { print(this); print(super); } bsh % foo(); 'this' reference (XThis) to Bsh object: foo 'this' reference (XThis) to Bsh object: global |
global.foo = 42; |
// Create a top level object to hold some state dataholder = object(); foo() { ... bar() { dataholder.value = 42; } bar(); print( dataholder.value ); } |
Tip: In the above example we used the BeanShell object() command to create an "empty" BeanShell scripted object context in which to hold some data. The object() command is just a standard empty method named object() that returns 'this'. The variable 'dataholder' above is a 'this' type reference and has all of the properties of any other BeanShell object scope. |
print( this ); // 'this' reference (XThis) to Bsh object: global // The following cases all synchronize on the same lock synchronized ( this ) { } // synchronized block synchronized int foo () { } // synchronized method foo() synchronized int bar () { } // synchronized method bar() int gee() { synchronized( super ) { } // synchronized blockinside gee() } |
Home | Back | Contents | Next |