Skip to content

Instantly share code, notes, and snippets.

@uemuraj
Created June 8, 2014 02:45
Show Gist options
  • Save uemuraj/d4a993e70f2e37df5920 to your computer and use it in GitHub Desktop.
Save uemuraj/d4a993e70f2e37df5920 to your computer and use it in GitHub Desktop.
Java のクラスを拡張する場合。元のクラスのインスタンスを参照するには、この書き方しかないのかなあ...
var File = Java.type("java.io.File");
function extendFile(spec) {
var ExtendFile = Java.extend(File);
var file = new ExtendFile(spec) {
toPath: function() {
return java.nio.file.Paths.get(Java.super(file).toURI());
}
}
return file;
}
var test = extendFile('test');
print();
print(test.toURL().class);
print(test.toURL());
print();
print(test.toURI().class);
print(test.toURI());
print();
print(test.toPath().class);
print(test.toPath());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment