Class DynamicObject

All Implemented Interfaces:

public abstract class DynamicObject extends Object implements TruffleObject
Represents a dynamic object, members of which can be dynamically added and removed at run time. To use it, extend DynamicObject and use DynamicObjectLibrary for object accesses. When constructing a DynamicObject, it has to be initialized with an empty initial shape. Initial shapes are created using Shape.newBuilder() and should ideally be shared per TruffleLanguage instance to allow shape caches to be shared across contexts. Subclasses can provide in-object dynamic field slots using the DynamicObject.DynamicField annotation and Shape.Builder.layout.


 public class MyObject extends DynamicObject implements TruffleObject {
     public MyObject(Shape shape) {

 Shape initialShape = Shape.newBuilder().layout(MyObject.class).build();

 MyObject obj = new MyObject(initialShape);
0.8 or earlier
See Also:
  • Constructor Details

    • DynamicObject

      protected DynamicObject(Shape shape)
      Constructor for DynamicObject subclasses. Initializes the object with the provided shape. The shape must have been constructed with a layout class assignable from this class (i.e., the concrete subclass, a superclass thereof, including DynamicObject) and must not have any instance properties (but may have constant properties).


       Shape shape = Shape.newBuilder().build();
       DynamicObject myObject = new MyObject(shape);
       Shape shape = Shape.newBuilder().layout(MyObject.class).build();
       DynamicObject myObject = new MyObject(shape);
      shape - the initial shape of this object
      IllegalArgumentException - if called with an illegal (incompatible) shape
  • Method Details