1

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?

2
  • How do you define an object? Is a C-struct an object?
    – mouviciel
    Aug 1, 2018 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, 2018 at 14:09

3 Answers 3

7

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

2
  • Thanks. Can you define a parameterized type in Rust?
    – Evan Aad
    Jul 31, 2018 at 19:11
  • 2
    Yes. That's what general-purpose generics are. Jul 31, 2018 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.

2
-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.

2
  • 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. Dec 24, 2018 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, 2018 at 19:51

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