Skip to content

Commit ca52506

Browse files
committed
nashorn samples
1 parent ebe8ada commit ca52506

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

res/nashorn2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ var Nashorn2 = Java.type('com.winterbe.java8.Nashorn2');
22
var result = Nashorn2.fun('John Doe');
33
print('\n' + result);
44

5+
Nashorn2.fun2(123);
6+
Nashorn2.fun2(49.99);
7+
Nashorn2.fun2(true);
8+
Nashorn2.fun2("hi there")
9+
Nashorn2.fun2(String("bam"))
10+
Nashorn2.fun2(new Number(23));
511
Nashorn2.fun2(new Date());
612
Nashorn2.fun2(new RegExp());
713
Nashorn2.fun2({foo: 'bar'});

src/com/winterbe/java8/Nashorn1.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static void main(String[] args) throws Exception {
2121
Invocable invocable = (Invocable) engine;
2222
Object result = invocable.invokeFunction("fun1", "Peter Parker");
2323
System.out.println(result);
24+
System.out.println(result.getClass());
2425

2526
invocable.invokeFunction("fun2", new Date());
2627
invocable.invokeFunction("fun2", LocalDateTime.now());

0 commit comments

Comments
 (0)