Академический Документы
Профессиональный Документы
Культура Документы
0b1
-----------------------------After several months of intense work I am pleased to announce the first beta
release of BeanShell 2.0. With version 2.0 BeanShell becomes a fully Java
compatible scripting language. BeanShell is now capable of interpreting
ordinary Java source and loading .java source files from the class path.
Although this code is still in beta I have been able to execute almost all of
the 165 example programs from my book (Learning Java, O'Reilly & Associates)
without modification as well as BeanShell's own ClassBrowser.java file.
The additional code to make this possible adds only about 30K to the size
of the package and the core minimal language distribution without class support
remains less than 150K.
BeanShell scripted classes are fully typed and appear to outside Java code and
via reflective inspection as ordinary classes. However their implementation is
fully dynamic and they may include arbitrary BeanShell scripts in their bodies,
methods, and constructors. Users may now freely mix loose, unstructured
BeanShell scripts, method closures, and full scripted classes. BeanShell
scripted classes are "bound" in the script namespace in which they are declared
and so can freely refer to other scripted items such as scripted methods,
commands, and "global" variables of the script. e.g.
// MyScript.bsh
count = 5;
class HelloWorld extends Thread {
public void run() {
for(i=0; i<count; i++)
print("Hello World!");
}
}
new HelloWorld().start();
All methods and constructors of the scripted classes delegate to the BeanShell
interpreter at runtime and all typed variables appear as true class members.
Loosely typed variables and methods may still be used inside the class but are
strictly private to the class body.
Previous limitations on the implementation of anonymous inner classes have also
been lifted, allowing BeanShell to extend arbitrary Java classes and implement
abstract base classes.
BeanShell 2.0 also brings with it two new language features:
JDK 1.5 style static class imports. You can import the static methods and
fields of a java Class into a BeanShell namespace. e.g.
static import java.lang.Math.*;
sqrt(4.0);
Instance object imports (mix-ins) with the importObject() command. You can
import the methods and fields of a Java object instance into a BeanShell
namespace. e.g.
Map map = new HashMap();
importObject( map );
put("foo", "bar");
print( get("foo") ); // "bar"