clamp API

clamp.method(return_type, arg_types=[], name=None)[source]

Decorate a clamp method with Java type information

  • return_type (java.lang.reflect.Type) – method return type
  • arg_types (array of java.lang.reflect.Type) – argument types that the method accepts
  • name (str) – alternative method name. You can use this to support polymorphism.


Simple method with Void.TYPE as the return type:

public void returnsVoid()
def returnsVoid(self):

This polymorphism example will generate a Java method with the following signature:

public int add(int a, int b)
public long add(long a, long b)
@clamp.method(int.TYPE, [int.TYPE, int.TYPE])
def add(self, a, b):
    return a + b
# we override the method name to "add", which will indicate that we want
# create a method with the same name
@clamp.method(long.TYPE, [long.TYPE, long.TYPE], name="add")
def addLong(self, a, b):
    return a_long + b_long

Declare what Java exceptions this method throws

Parameters:exceptions (a list of java.lang.Throwable) – accepts a list of exceptions as arguments


public void writeList() throws IOException, NoSuchFieldException
@clamp.throws(IOException, NoSuchFieldException)
def writeList(self):
    raise IOException("message")
    raise NoSuchFieldException("other message")
clamp.annotated(annotation, **kwargs)[source]

Annotate the Java version of the method with Java annotation

  • annotation (java.lang.annotation.Annotation) – Java annotation
  • kwargs (java.lang.Object) – keword arguments to pass to the annotation

Example annotation:

public void test()
def test(self):