mirror of
https://github.com/morluto/awesome-reverse-engineering.git
synced 2026-12-02 13:11:19 -05:00
7c17a14706
Adds a CFR 0.152 example next to Vineflower: a synthetic Java 17 fixture with a sealed interface, records, instanceof patterns, switch yield and a text block is decompiled by the pinned release JAR (SHA-256 checked) and rebuilt, and prints the same line. A reflection probe shows that by default the rebuilt interface is no longer sealed, and --sealed true restores it, matching CFR's option defaults for Java 17 class files. The CFR entry now names the flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019S6gW1R7hWkvBKbBYnSYgK
41 lines
1.2 KiB
Java
41 lines
1.2 KiB
Java
public class Shapes {
|
|
sealed interface Shape permits Circle, Square, Rect {}
|
|
record Circle(int r) implements Shape {}
|
|
record Square(int side) implements Shape {}
|
|
record Rect(int w, int h) implements Shape {}
|
|
|
|
static int area(Shape s) {
|
|
if (s instanceof Circle c && c.r() > 0) return 3 * c.r() * c.r();
|
|
if (s instanceof Square q) return q.side() * q.side();
|
|
if (s instanceof Rect r) return r.w() * r.h();
|
|
return -1;
|
|
}
|
|
|
|
static String label(int n) {
|
|
return switch (n % 4) {
|
|
case 0 -> "zero";
|
|
case 1 -> {
|
|
String t = "one";
|
|
yield t + n;
|
|
}
|
|
default -> {
|
|
if (n < 0) yield "neg";
|
|
yield "many";
|
|
}
|
|
};
|
|
}
|
|
|
|
static final String BANNER = """
|
|
shapes
|
|
v1
|
|
""";
|
|
|
|
public static void main(String[] args) {
|
|
Shape[] all = {new Circle(2), new Circle(0), new Square(3), new Rect(2, 5)};
|
|
StringBuilder out = new StringBuilder(BANNER.replace("\n", "|"));
|
|
for (Shape s : all) out.append(area(s)).append(',');
|
|
for (int n : new int[]{0, 1, 5, -3, 6}) out.append(label(n)).append(',');
|
|
System.out.println(out);
|
|
}
|
|
}
|