Re:Dynamic type systems are not inherently more open
by tsimionescu on Sunday January 19, 2020 @07:51AM
(#22091173)
Hmm, that may be true for JSON, but I think that Java binary serialization holds enough information about the original types to allow deserialization without having to explicitly pass the expected class (though what the runtime system does behind the scenes may be equivalent).
Re:Dynamic type systems are not inherently more open
by mmis1000 on Sunday January 19, 2020 @09:42AM
(#22091647)
Java will crash if type actually does not match at runtime. You can do whatever cast you want to it ,but it is not necessary to work.
And kotlin even includes a key word to say: if cast does not work, just return null.
Is that actually true in Java? It seems to me that the way that you'd implement that load() method is by using generics to inspect the class you were passed, figuring out what data it wants in what slot, and pulling that data in from the input. You could hold on to the input and return a dynamic proxy, and you would be able to see when someone calls a getFoo() on that proxy, but then you wouldn't know what the type of the foo it expects is. And I don't know whether you could even make your proxy assignable to T.