4 ms·
> There's no way in Java, Rust or C++ to express this, praised be the language designers. That's not even the case. In Java, you'd just use Object, which is fo
by int_19h 2y ago
> There's no way in Java, Rust or C++ to express this, praised be the language designers.
That's not even the case. In Java, you'd just use Object, which is for all practical purposes equivalent to `interface{}` aka `any` in Go. And then you downcast. Indeed, code exactly like this was necessary in Java to work with collections before generics were added to the language.
In C++, there's no common supertype, but there std::any, which can contain a value of any type and be downcast if you know what the actual type is.