2024-10-01 15:28:20 +00:00
|
|
|
import java.lang.Integer;
|
|
|
|
import java.lang.Double;
|
|
|
|
import java.lang.Number;
|
|
|
|
|
|
|
|
public record R(Number n) {}
|
|
|
|
|
|
|
|
public class SwitchOverload {
|
|
|
|
|
|
|
|
Number f(Double d) { return d * 2; }
|
|
|
|
Number f(Integer i) { return i * 5; }
|
|
|
|
|
2024-10-02 13:09:19 +00:00
|
|
|
public m(r, x) {
|
|
|
|
x = x + x;
|
2024-10-01 15:28:20 +00:00
|
|
|
return switch(r) {
|
2024-10-02 13:09:19 +00:00
|
|
|
case R(o) -> {
|
|
|
|
x = x + x;
|
|
|
|
yield f(o);
|
|
|
|
}
|
2024-10-01 15:28:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|