record X<T>(T t) {
@Override
public String toString() {
String s = t.getClass().getName();
s = "%s<%s>".formatted(getClass().getName(), s);
return "%s@%x".formatted(s, identityHashCode(this));
}
}
X<?> x = new X<>(123);
out.print(x);
package Point {
my $_data = {};
sub new {
my $class = shift;
$_data = { @_ };
bless $_data, $class;
};
use overload '""' => sub { shift->_stringify() };
sub _stringify {
my $self = shift;
return sprintf 'A point at (%d, %d)', $self->{x}, $self->{y};
}
}
my $p = Point->new(x => 5, y => 10);
print $p;