4 ms·
> Scala needs to interoperate with other Java languages But does it? Can I even use e.g. a Scala collection from Java? (let alone Clojure, Kotlin, etc) Certain
by willtim 9y ago
> Scala needs to interoperate with other Java languages
But does it? Can I even use e.g. a Scala collection from Java? (let alone Clojure, Kotlin, etc)
Certainly it looks easy to import and use Java objects, but that looks to be the extent of it.
> it couldn't be statically known at compile time in the case where a library written in Scala is being called by code that was written at a later date
When you build some new code that uses an existing library, any parametric polymorphic type variables get instantiated at the use sites. Where I admit this isn't true, is the adhoc polymorphic dynamic dispatch via subtyping, but this wasn't given to me as an example. I don't see that ArrayLists and ADTs should present a problem.
> types still cannot be statically known in cases where you're being handed objects whose type is not determined until run time
Again, I think you are referring to dynamic dispatch here? I agree this could be a problem in open class hierarchies. But the ADT encoding in Scala is a closed statically-known hierarchy, so I can't see why it has to cause problems.
Truly "generic" or parametric polymorphic code should not depend on type tags or even be allowed to introspect the runtime type, doing so violates parametricity, which ultimately reduces our ability to reason about the code.
- bunderbunder 9y ago> Can I even use e.g. a Scala collection from Java? (let alone Clojure, Kotlin, etc) Yup to all. Sometimes the code comes out looking a bit ugly (e.g, you can access default parameters from Java, but it's done by calling methods with kind of awful auto-generated names), but the only things you really can't get at are things that relies on implicits, type tags, or traits with fields.