조건결과

2026년 1월 28일 15:09분

package com.jesusbornd.exodus;

import java.util.ArrayList;
import java.util.List;

public class Exodus_21_Chapter_Lv2 {

    static class Clause {
        final boolean when;
        final String then;

        Clause(boolean when, String then) {
            this.when = when;
            this.then = then;
        }

        String apply() {
            return when ? then : null;
        }
    }

    public static void main(String[] args) {
        List<Clause> clauses = new ArrayList<>();
        clauses.add(new Clause(true, "배상 / Restitution"));
        clauses.add(new Clause(false, "면제 / Exemption"));
        clauses.add(new Clause(true, "회복 / Restoration"));

        for (Clause c : clauses) {
            String out = c.apply();
            if (out != null) System.out.println(out);
        }
    }
}

from dataclasses import dataclass

@dataclass(frozen=True)
class Clause:
    when: bool
    then: str

    def apply(self):
        return self.then if self.when else None

clauses = [
    Clause(True, "배상 / Restitution"),
    Clause(False, "면제 / Exemption"),
    Clause(True, "회복 / Restoration"),
]

for c in clauses:
    out = c.apply()
    if out is not None:
        print(out)

Comments

Avatar
 2026년 1월 28일 15:10분

“면제”가 false로 빠진 게 아이러니하게 현실감 있음.



Search

← 목록으로