Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd4b8c3

Browse files
committed
add more api extension samples
1 parent7d8c0cc commitbd4b8c3

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

‎res/nashorn4.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,52 @@ print(__FILE__, __LINE__, __DIR__);
4646

4747
// java import
4848

49-
varimports=newJavaImporter(java.util,java.io);
49+
varimports=newJavaImporter(java.io);
5050
with(imports){
51-
varmap=newHashMap();
52-
}
51+
varfile=newFile(__FILE__);
52+
print(file.getPath());
53+
}
54+
55+
56+
// convert iterable to js array
57+
58+
varlist=newjava.util.ArrayList();
59+
list.add("s1");
60+
list.add("s2");
61+
list.add("s3");
62+
63+
varjsArray=Java.from(list);
64+
print(jsArray);
65+
print(Object.prototype.toString.call(jsArray));
66+
67+
68+
// convert js array to java array
69+
70+
varjavaArray=Java.to([3,5,7,11],"int[]");
71+
print(javaArray.class);
72+
73+
74+
// calling super
75+
76+
varSuperRunner=Java.type('com.winterbe.java8.SuperRunner');
77+
varRunner=Java.extend(SuperRunner);
78+
79+
varrunner=newRunner(){
80+
run:function(){
81+
Java.super(runner).run();
82+
print('on my run');
83+
}
84+
}
85+
runner.run();
86+
87+
88+
89+
// load
90+
91+
load('http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js');
92+
93+
varodds=_.filter([1,2,3,4,5,6],function(num){
94+
returnnum%2==1;
95+
});
96+
97+
print(odds);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.winterbe.java8;
2+
3+
/**
4+
* @author Benjamin Winterberg
5+
*/
6+
publicclassSuperRunnerimplementsRunnable {
7+
8+
@Override
9+
publicvoidrun() {
10+
System.out.println("super run");
11+
}
12+
13+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp