2023-08-18 15:15:15 +00:00
|
|
|
import java.lang.Integer;
|
2023-09-01 10:34:43 +00:00
|
|
|
import java.lang.Number;
|
|
|
|
import java.lang.Float;
|
2023-08-18 15:15:15 +00:00
|
|
|
|
2023-09-01 10:34:43 +00:00
|
|
|
record Point(Number x, Number y) {}
|
2023-08-18 15:15:15 +00:00
|
|
|
|
|
|
|
public class OverloadPattern {
|
|
|
|
m(Point(Integer x, Integer y)) {
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2023-09-01 10:34:43 +00:00
|
|
|
m(Point(Float x, Float y)) {
|
|
|
|
return x * y;
|
|
|
|
}
|
|
|
|
|
2023-08-18 15:15:15 +00:00
|
|
|
m(Integer x) {
|
|
|
|
return x;
|
|
|
|
}
|
2023-09-01 10:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
public class OverloadPattern {
|
|
|
|
Integer m$Point$_$java$lang$Integer$_$java$lang$Integer$_$(Point point) {
|
|
|
|
var x = point.x();
|
|
|
|
var y = point.y();
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Float m$Point$_$java$lang$Float$_$java$lang$Float$_$(Point point) {
|
|
|
|
var x = point.x();
|
|
|
|
var y = point.y();
|
|
|
|
return x * y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object m(Point point) {
|
|
|
|
switch(point) {
|
|
|
|
case Point(Integer x, Integer y) ->
|
|
|
|
m$Point$_$java$lang$Integer$_$java$lang$Integer$_$(point);
|
|
|
|
case Point(Float x, Float y) ->
|
|
|
|
m$Point$_$java$lang$Float$_$java$lang$Float$_$(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Integer m(Integer x) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|