Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

pi/agent/skills/optional/java/java-class-file-api/examples/jep-484.md

Raw
Rendered preview

JEP 484 examples

Source: https://openjdk.org/jeps/484

byte[] newBytes = ClassFile.of().transformClass(bytes, (builder, element) -> {
    if (element instanceof MethodModel m && m.methodName().stringValue().startsWith("debug")) {
        return; // drop method
    }
    builder.with(element);
});
ClassModel model = ClassFile.of().parse(bytes);
for (MethodModel method : model.methods()) {
    System.out.println(method.methodName().stringValue());
}
# [JEP 484](https://openjdk.org/jeps/484) examples

Source: https://openjdk.org/jeps/484

```java
byte[] newBytes = ClassFile.of().transformClass(bytes, (builder, element) -> {
    if (element instanceof MethodModel m && m.methodName().stringValue().startsWith("debug")) {
        return; // drop method
    }
    builder.with(element);
});
```

```java
ClassModel model = ClassFile.of().parse(bytes);
for (MethodModel method : model.methods()) {
    System.out.println(method.methodName().stringValue());
}
```