user3578021
user3578021

Reputation: 103

add new properties to java pojo in nashorn

in nashorn, i try to accomplish something like this

a.test = function(key){print(key);};

but variable a is java entity(pojo), when i do

a.test( "someting" );

it give me error

amavisca.monsterpuzzle.entity.a@adfbc1 has no such function "test"

my question :

how to add java pojo, new properties in nashorn?

example :

 a.test = function(key){print(key);};

Upvotes: 1

Views: 231

Answers (1)

Attila Szegedi
Attila Szegedi

Reputation: 4595

You can't. POJOs in Nashorn act as if they were sealed JS objects (they are non-extensible and their properties are non-configurable, same as if they had Object.seal(obj) called on them).

Upvotes: 2

Related Questions