-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathClassFileApi.java
More file actions
26 lines (24 loc) · 842 Bytes
/
Copy pathClassFileApi.java
File metadata and controls
26 lines (24 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 25+
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.nio.file.Files;
import java.nio.file.Path;
/// Proof: class-file-api
/// Source: content/tooling/class-file-api.yaml
void main() throws Exception {
Path classFile = Files.createTempFile("ClassFileApi", ".class");
try (var compiledClass =
getClass().getResourceAsStream("ClassFileApi.class")) {
Files.copy(compiledClass, classFile,
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
}
try {
ClassModel model = ClassFile.of().parse(classFile);
model.methods().forEach(method ->
System.out.println(
method.methodName().stringValue()));
} finally {
Files.delete(classFile);
}
}