0

The GO programming language has objects but no inheritance. It also has generics for the built-in types Array and Map. Is there a programming language with objects but no inheritance and with generics (i.e. parameterized types) for all user created types?

  • How do you define an object? Is a C-struct an object? – mouviciel Aug 1 '18 at 10:24
  • 1
    @mouviciel: An object is a value with a type, data fields and methods, and an identity that is distinct from all other objects of the same type. If C-structs have methods, they're probably objects. – Evan Aad Aug 1 '18 at 14:09
6

Rust has objects and general-purpose generics but not inheritance.

  • Thanks. Can you define a parameterized type in Rust? – Evan Aad Jul 31 '18 at 19:11
  • 2
    Yes. That's what general-purpose generics are. – Sebastian Redl Jul 31 '18 at 19:25
-2

I know JavaScript has objects and generics in the form of generic objects but it doesn't have inheritance if you're referring to the Java or C# way of inheritance since it really a prototypical language. But you can use JavaScript generic objects to achieve basically the generics you're looking for.

  • 1
    JavaScript doesn't have types, let alone generics. You are correct that JavaScript uses a prototype-based object system, but it still has a notion of inheritance via the prototype chain. – Derek Elkins Dec 24 '18 at 21:22
  • Sorry I just updated it to reflect how JavaScript does have a form of generics. – gdavis Dec 24 '18 at 21:40
-3

Kotlin is a language too that allows for things like generics and objects as it was meant to interface and call Java code in kotlin but it doesn't support inheritance at all. You have to use interfaces which they can have concrete types but this is as close as one can get to inheritance with kotlin.

  • The first section in the introductory documentation for Kotlin about classes is "Classes and Inheritance" which illustrates classes deriving from other classes and overriding (non-abstract) methods. – Derek Elkins Dec 24 '18 at 19:30
  • Thank you for the information. Here is an update to my original comment: JavaScript is a language too that allows for things like generics and objects but doesn't have inheritance at all. The most one can do is use object cloning and one can reference and use another objects function(s) but there is no inheritance with JavaScript as it is with Java or C#. – user324226 Dec 24 '18 at 19:51

protected by gnat Dec 24 '18 at 21:43

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.