3 ms·
Introspection like this usually is a hack around (1) having a weak type system (2) using objects wrong. That said, T.class and instanceOf work perfectly fine in
by kazagistar 12y ago
Introspection like this usually is a hack around (1) having a weak type system (2) using objects wrong. That said, T.class and instanceOf work perfectly fine in Haskell and such, because of the lack of inheritance in the OOP sense. Instead, they just say "if you want to get a type, implement the Typeable interface, which has a method that returns the Type". In other words, if you want it, do it manually, with the added benefit that there is 0 cost, memory or otherwise interfaces when they aren't used.
Really, a quote I heard once: "Java is like a strawman built specially by people who want to argue against using strong type systems."