The only reason that Integer.class
is useful in Java, is because Java implements reflection:
- the runtime has a description of all existing types
- for each type, it has a description of all attributes and methods
and therefore the virtual machine can, at runtime, create an instance of a type from thin air.
Automatic, pervasive reflection violates at least one core tenet of Rust:
You don't pay for what you don't use.
so has not been implemented.
Rust has some amount of reflection still:
- it has compile-time reflection, via plugins
- it has some type information, via
TypeId
However, the former does not incur any memory/performance overhead and the latter is on a pay-per-use basis.
As far as I know, there is no proposal to significantly extend reflection yet. Even down-casting is for now explored as a library, and not a language, option (see the query_interface crate).