Skip to content

toString() to act as __str__() #245

@cyraid

Description

@cyraid
public class MyClass {
  private final String str;
  public MyClass(String str) {
    this.str = str;
  }
  @Override
  public String toString() {
    return str;
  }
}

I would expect calling:

context.getPolyglotBindings().putMember("obj", new MyClass("HI"));
context.eval("python",
  """
  import polyglot
  obj = polyglot.import_value("obj")
  print(obj)
  """);

That it would print "HI" and not <JavaObject[MyClass] at 0xdeadbeef>

Is there a way to make it print it as a string? I've tried using Python's str().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions