examples of polymorphism by balu051989

VIEWS: 12 PAGES: 18

									Examples

C++                                                                                                                               [edit]

  #include <iostream>
  #include <string>

  using namespace std;

  class Animal
  {
          public:
          Animal(const string& name) : name(name) {}
          virtual string talk() = 0;
          const string name;
  };

  class Cat : public Animal
  {
          public:
          Cat(const string& name) : Animal(name) {}
          virtual string talk() { return "Meow!"; }
  };

  class Dog : public Animal
  {
          public:
          Dog(const string& name) : Animal(name) {}
          virtual string talk() { return "Arf! Arf!"; }
  };

  // prints the following:
  //
  // Missy: Meow!
  // Mr. Mistoffelees: Meow!
  // Lassie: Arf! Arf!!
  //
  int main()
  {
          Animal* animals[] =
          {
                  new Cat("Missy"),
                  new Cat("Mr. Mistoffelees"),
                  new Dog("Lassie")
          };

             for(int i = 0; i < 3; i++)
             {
                     cout << animals[i]->name << ": " << animals[i]->talk() << endl;
                     delete animals[i];
             }
             return 0;
  }

Note that the talk() method is explicitly declared as virtual. This is because non-polymorphic method calls are very efficient in
C++ and a polymorphic method call is roughly equivalent to calling a function through a pointer stored in an array. [3] To take
advantage of the efficiency of non-polymorphic calls, all method calls are treated as non-polymorphic, unless explicitly marked
as virtual by the developer.

Common Lisp                                                                                                                       [edit]
Polymorphism in Common Lisp is provided via the Common Lisp Object System.

  (defclass animal ()
    ((name :initarg :name :accessor name)))

  (defclass cat (animal) ())

  (defclass dog (animal) ())

  (defgeneric talk      (animal))

  (defmethod     talk ((animal cat)) "Meow!")

  (defmethod     talk ((animal dog)) "Woof! Woof!")

  (defparameter *animals*
    (list (make-instance 'cat :name "Missy")
          (make-instance 'cat :name "Mr. Mistoffelees")
          (make-instance 'dog :name "Lassie")))

  (dolist (animal *animals*)
    (format t "~%~a: ~a" (name animal) (talk animal)))


Java                                                                                       [edit]

  // from file Animal.java
  package org.wikipedia.examples;

  public class Animal {
          private String name;

            public Animal(String name) {
                    this.setName(name);
            }

          public String talk() {
                  throw new UnsupportedOperationException("animals can't talk (except in
  cartoons)");
          }

            public void setName(String name) {
                    this.name = name;
            }

            public String getName() {
                    return name;
            }
  }

  // from file Cat.java
  package org.wikipedia.examples;

  import org.wikipedia.examples.Animal;

  public class Cat extends Animal {

            public Cat(String name) {
                    super(name);
            }

            @Override
            public String talk() {
                    return "Meow!";
           }
 }

 // from file Dog.java
 package org.wikipedia.examples;

 import org.wikipedia.examples.Animal;

 public class Dog extends Animal {

           public Dog(String name) {
                   super(name);
           }

           @Override
           public String talk() {
                   return "Woof! Woof!";
           }
 }

 // from file SubtypePolymorphismExample.java
 package org.wikipedia.examples;

 import   java.io.IOException;
 import   java.util.ArrayList;
 import   org.wikipedia.examples.Animal;
 import   org.wikipedia.examples.Cat;
 import   org.wikipedia.examples.Dog;

 public class SubtypePolymorphismExample {
         private ArrayList<Animal> animals = new ArrayList<Animal>();

         public SubtypePolymorphismExample() {
                 Animal missy = new Cat("Missy"); // a Cat IS_A Animal, so you can assign to a
 superclass variable
                 // Cat nightmare = new Animal("Nightmare"); // but this is illegal, because
 not all animals are cats
                 Cat mr = new Cat("Mr. Mistophelees");
                 Dog lassie = new Dog("Lassie");
                 animals.add(missy);
                 animals.add(mr);
                 animals.add(lassie);
         }

           public ArrayList<Animal> getAnimals() {
                   return animals;
           }

           public static void main(String[] args) throws IOException {
                   SubtypePolymorphismExample example = new SubtypePolymorphismExample();
                   for (Animal a : example.getAnimals()) {
                           System.out.println(a.getName() + " says: " + a.talk());
                   }
           }

 }

 //   When you run this, the output is:
 //   Missy says: Meow!
 //   Mr. Mistophelees says: Meow!
 //   Lassie says: Woof! Woof!


PHP                                                                                         [edit]
 <?php

 interface IAnimal
 {
     function getName();
     function talk();
 }

 abstract class AnimalBase implements IAnimal
 {
     protected $name;

      public function __construct($name)
      {
          $this->name = $name;
      }

      public function getName()
      {
          return $this->name;
      }
 }

 class Cat extends AnimalBase
 {

      public function talk()
      {
          return "Meowww!";
      }
 }

 class Dog extends AnimalBase
 {

      public function talk()
      {
          return "Arf! Arf!";
      }
 }

 $animals = array(
     new Cat("Missy"),
     new Cat("Mr. Mistoffelees"),
     new Dog("Lassie")
 );

 foreach ($animals as $animal) {
     echo $animal->getName() . ": " . $animal->talk();
 }

 ?>


Python                                                   [edit]

 myString = 'Hello, world!'
 myList = [0, 'one', 1, 'two', 3, 'five', 8]

 print myString[:5]   # prints Hello
 print myList[:5]     # prints [0, 'one', 1, 'two', 3]

 print 'e' in myString     # prints True
 print 5 in myList         # prints False
However, the most common examples of polymorphism are found in custom classes. Consider the example below, where two
subclasses (Cat and Dog) are derived from an Animalsuperclass. Two Cat objects and one Dog are instantiated and given
names, and then they are gathered in an array animals and their talk() method is called.

  class Animal:
      def __init__(self, name):    # Constructor of the class
          self.name = name
      def talk(self):              # Abstract method, defined by convention only
          raise NotImplementedError("Subclass must implement abstract method")

  class Cat(Animal):
      def talk(self):
          return 'Meow!'

  class Dog(Animal):
      def talk(self):
          return 'Woof! Woof!'

  animals = [Cat('Missy'),
             Cat('Mr. Mistoffelees'),
             Dog('Lassie')]

  for animal in animals:
      print animal.name + ': ' + animal.talk()

  #   prints the following:
  #
  #   Missy: Meow!
  #   Mr. Mistoffelees: Meow!
  #   Lassie: Woof! Woof!

Note that Python makes polymorphism particularly easy to write, since the language is dynamically (and implicitly) typed: a name
can be bound to objects of any type (or class) without having to explicitly specify the type, and a list holds mixed type (unlike a
C array or a Java array, be it generic or not).

JavaScript                                                                                                                      [edit]

  function Animal(name) {
          this.name = name;
          this.talk = function () {
                  return "";
          };
  }

  function Cat(name) {
          Animal.call(this, name);
          this.talk = function() {
                  return "Meow!!!";
          };
  }

  function Dog(name) {
          Animal.call(this, name);
          this.talk = function() {
                  return "Arf! Arf!";
          };
  }

  var animals = [
          new Cat("Missy"),
          new Cat("Mr. Mistoffelees"),
            new Dog("Lassie")
  ];

  //   prints the following:
  //
  //   Missy: Meow!!!
  //   Mr. Mistoffelees: Meow!!!
  //   Lassie: Arf! Arf!

  animals.forEach(function(animal) {
          print(animal.name+": "+animal.talk());
  });


Squirrel                                                             [edit]

Squirrel supports polymorphism.

  class Animal {
          constructor(thename)
          {
                  name = thename;
          }
          function talk()
          {
                  throw "animals can't talk (except in cartoons)";
          }
          name = null;
  };

  class Cat extends Animal {
          function talk()
          {
                  return "Meow!";
          }
  };

  class Dog extends Animal {
          function talk()
          {
                  return "Woof! Woof!";
          }
  };

  local animals = [
          Cat("Missy"),
          Cat("Mr. Mistoffelees"),
          Dog("Lassie")
  ];

  foreach(animal in animals)
  {
          print(animal.name+": "+animal.talk()+"\n");
  }


Delphi/DEEP                                                          [edit]

  unit polymorphism;

  interface

  type
    TAnimalBase = class( TObject )
    private
       fName : string
     public
       constructor Create( aName : string ); virtual;
       function Talk : string; virtual; abstract;
       property Name : string read fName;
     end;

     TCat = class( TAnimalBase )
     public
       function Talk : string; override;
     end;

     TDog = class( TAnimalBase )
     public
       function Talk : string; override;
     end;

  implementation

  constructor TAnimalBase.Create( aName : string );
  begin
    fName := aName;
  end;

  function TCat.Talk : string;
  begin
    result := 'Meowww!';
  end;

  function TDog.Talk : string;
  begin
    result := 'Arf! Arf!';
  end;

  end.


Eiffel                                                                                                                       [edit]

This example shows the class ANIMAL and its descendants, classes CAT and DOG. These classes are clients of a
class TEST_ANIMALS which creates a polymorphic list of objects of type ANIMAL containing two instances of CAT and one of DOG.
Then the list is traversed applying the features name and talk to each list item. Dynamic binding ensures that the proper version
of talk is selected at runtime.

  deferred class
      ANIMAL
  feature
      name: STRING

         talk: STRING
             deferred
             end

         make (a_name: STRING)
             do
                 name := a_name
             end
  end

  class
      CAT
  inherit
      ANIMAL
  create
      make
  feature
      talk: STRING
           do
               Result := "Meowww!"
           end
  end

  class
      DOG
  inherit
      ANIMAL
  create
      make
  feature
      talk: STRING
           do
               Result := "Arf! Arf!"
           end
  end

  class
      TEST_ANIMALS
  create
      make
  feature
      make
           do
              create animal_list.make
              animal_list.extend (create {CAT}.make ("Missy"))
              animal_list.extend (create {CAT}.make ("Mr. Mistoffelees"))
              animal_list.extend (create {DOG}.make ("Lassie"))

                     across animal_list as cs loop
                         print (cs.item.name + ": " + cs.item.talk + "%N")
                     end

              end

        animal_list: LINKED_LIST [ANIMAL]

  end

Point of interest:
   The class ANIMAL is marked deferred (a term analogous to abstract in some other languages.) Eiffel has comprehensive
   support for multiple inheritance. Consequently, it does not support the concept of interface as implemented in C# and Java. In
   class ANIMAL, the function talk is marked as deferred, meaning that any effective (analogous toconcrete) descendant must
   provide an implementation for talk. This is conceptually equivalent to what happens with interfaces. But the attribute name,
   and the initialization procedure make are given implementations in class ANIMAL.

Perl                                                                                                                          [edit]
Polymorphism in Perl is inherently straightforward to write because of the language's use of sigils and references. This is
the Animal example in standard OO Perl:

  package Animal;
  sub new {
      my ($class, $name) = @_;
      bless {name => $name}, $class;
  }

  package Cat;
  @ISA = "Animal";
  sub talk {"Meow"}

  package Dog;
  @ISA = "Animal";
  sub talk {"Woof! Woof!"}

  package main;
  my @animals = (
      Cat->new("Missy"),
      Cat->new("Mr. Mistoffelees"),
      Dog->new("Lassie"),
  );
  for my $animal (@animals) {
      print $animal->{name} . ": " . $animal->talk . "\n";
  }

  #   prints the following:
  #
  #   Missy: Meow
  #   Mr. Mistoffelees: Meow
  #   Lassie: Woof! Woof!

This means that Perl can also apply polymorphism to the method call. The example below is written using the Moose module in
order to show modern OO practises in Perl (it is not required for method polymorphism):

  {
        package Animal;
        use Moose;
        has 'name' => ( isa => 'Str', is => 'ro' );
  }

  {
        package Cat;
        use Moose;
        extends 'Animal';
        sub talk { 'Meow' }
        sub likes { 'Milk' }
  }

  {
        package Dog;
        use Moose;
        extends 'Animal';
        sub talk { 'Woof! Woof!' }
        sub likes { 'Bone' }
  }

  my @animals =     (
      Cat->new(     name => 'Missy' ),
      Cat->new(     name => 'Mr. Mistoffelees' ),
      Dog->new(     name => 'Lassie' ),
  );

  for my $animal ( @animals ) {
      for my $trait qw/talk likes/ {
          print $animal->name . ': ' . $trait . ' => ' . $animal->$trait;
      }
  }

  # prints the following:
  #
  # Missy: talk => Meow
  #   Missy: likes => Milk
  #   Mr. Mistoffelees: talk => Meow
  #   Mr. Mistoffelees: likes => Milk
  #   Lassie: talk => Woof! Woof!
  #   Lassie: likes => Bone


C#                                                                                                                              [edit]

Because C# only supports single-inheritance in the hierarchy of instantiatable classes, the ideal implementation of polymorphism in
C# uses interface inheritance. Multiple interfaces--which can themselves inherit from other interfaces--can be attached to a class in
an ad-hoc fashion, but they can only define behavior, not implement it. In the following example, the interface is stored in a
common class API which has no user code dependencies.

  // Assembly: Common Classes
  namespace CommonClasses
  {
      public interface IAnimal
      {
          string Name { get; }
          string Talk();
      }
  }

  // Assembly: Animals
  using System;
  using CommonClasses;

  namespace Animals
  {
      public abstract class AnimalBase
      {
          public string Name { get; private set; }

             protected AnimalBase(string name) {
                 Name = name;
             }
        }

        public class Cat : AnimalBase, IAnimal
        {
            public Cat(string name) : base(name) {
            }

             public string Talk() {
                 return "Meowww!";
             }
        }

        public class Dog : AnimalBase, IAnimal
        {
            public Dog(string name) : base(name) {
            }

             public string Talk() {
                 return "Arf! Arf!";
             }
       }
  }

  // Assembly: Program
  // References and Uses Assemblies: Common Classes, Animals
  using System;
  using System.Collections.Generic;
  using Animals;
  using CommonClasses;

  namespace Program
  {
      public class TestAnimals
      {
          // prints the following:
          //   Missy: Meowww!
          //   Mr. Mistoffelees: Meowww!
          //   Lassie: Arf! Arf!
          //
          public static void Main(string[] args)
          {
              var animals = new List<IAnimal>() {
                  new Cat("Missy"),
                  new Cat("Mr. Mistoffelees"),
                  new Dog("Lassie")
              };

                foreach (var animal in animals) {
                    Console.WriteLine(animal.Name + ": " + animal.Talk());
                }
            }
       }
  }


Visual Basic .NET                                                                 [edit]

Here is the VB.NET way to implement the above C#.NET example code:

  ' Assembly: CommonClasses (Class Library)
  Namespace CommonClasses
      Public Interface IAnimal
          ReadOnly Property Name() As String
          Function Talk() As String
      End Interface
  End Namespace

  ' Assembly: Animals (Class Library)
  ' References: CommonClasses
  Namespace Animals

       Public MustInherit Class AnimalBase
           Implements IAnimal

            Private mName As String

            Public Sub New(ByVal AnimalName As String)
                mName = AnimalName
            End Sub

            Public ReadOnly Property Name() As String Implements IAnimal.Name
                Get
                    Return mName
                End Get
            End Property

           Public Overridable Function Talk() As String Implements IAnimal.Talk
               Return "Hello World den...!"
           End Function
       End Class

       Public Class Cat
            Inherits AnimalBase

            Public Sub New(ByVal AnimalName As String)
                MyBase.New(AnimalName)
            End Sub

           Public Overrides Function Talk() As String
               Return "Meowww!"
           End Function
       End Class

       Public Class Dog
           Inherits AnimalBase

            Public Sub New(ByVal AnimalName As String)
                MyBase.New(AnimalName)
            End Sub

           Public Overrides Function Talk() As String
               Return "Arf! Arf!"
           End Function
       End Class

  End Namespace

  ' Assembly: Program (Console Application)
  ' References: CommonClasses and Animals
  Imports Animals
  Imports CommonClasses

  Public Module TestAnimals

       ' prints the following:
       '   Missy: Meowww!
       '   Mr. Mistoffelees: Meowww!
       '   Lassie: Arf! Arf!
       '
       Sub Main()

            Dim animals As List(Of IAnimal) = New List(Of IAnimal)
            animals.Add(New Cat("Missy"))
            animals.Add(New Cat("Mr. Mistoffelees"))
            animals.Add(New Dog("Lassie"))

            For Each animal As IAnimal In animals
                 Console.WriteLine(animal.Name & ": " & animal.Talk())
            Next

            Console.WriteLine("Press any key to continue...")
            Console.ReadKey(True)

       End Sub

  End Module

One way of doing polymorphism is through the definition and implementation of a common interface. Consider the example below,
where two subclasses (Cat and Dog) implement theIAnimal interface. Two Cat objects and one Dog are instantiated and given
names, and then they are gathered in a list and their Talk() method is called.

  Namespace std

       Public Interface IAnimal
           ReadOnly Property Name() As String
        Function Talk() As String
    End Interface

    Public Class Cat
        Implements IAnimal

        Private mName As String

        Sub New(ByVal name As String)
            mName = name
        End Sub

        Public ReadOnly Property Name() As String Implements IAnimal.Name
            Get
                Return mName
            End Get
        End Property

        Public Function Talk() As String Implements IAnimal.Talk
            Return "Meow!"
        End Function
    End Class

    Public Class Dog
        Implements IAnimal

        Private mName As String

        Sub New(ByVal name As String)
            mName = name
        End Sub

        Public ReadOnly Property Name() As String Implements IAnimal.Name
            Get
                Return mName
            End Get
        End Property

        Public Function Talk() As String Implements IAnimal.Talk
            Return "Arf! Arf!"
        End Function
    End Class

    Public Module TestAnimals

        ' Prints the following:
        '
        ' Missy: Meow!
        ' Mr. Mistoffelees: Meow!
        ' Lassie: Arf! Arf!
        Public Sub Main()
            Dim animals(2) As IAnimal
            animals(0) = New Cat("Missy")
            animals(1) = New Cat("Mr. Mistoffelees")
            animals(2) = New Dog("Lassie")

            For Each a As IAnimal In animals
                Console.Out.WriteLine("{0}: {1}", a.Name, a.Talk)
            Next a

        End Sub
    End Module

End Namespace
Xbase++                                                   [edit]

 #include "class.ch"
 //
 // This program prints:
 //
 // Missy Meow!
 // Mr. Mistoffelees Meow!
 // Lassie Bark!
 // Press any key to continue...
 //

 /////////////////////////////
 //
 PROCEDURE Main(1)
 //
 /////////////////////////////

   LOCAL aAnimals := Array(3)
   LOCAL i

   aAnimals[1] :=    Cat():New("Missy")
   aAnimals[2] :=    Cat():New("Mr. Mistoffelees")
   aAnimals[3] :=    Dog():New("Lassie")

   FOR i:=1 TO LEN(aAnimals)
      ? aAnimals[i]:Name + "     " + aAnimals[i]:Talk()
   NEXT i

   WAIT

 RETURN

 /////////////////////////////
 //
 CLASS Animal
 //
 /////////////////////////////

    EXPORTED:
       VAR Name      READONLY

       METHOD Init
       DEFERRED CLASS METHOD Talk
 ENDCLASS

 METHOD Animal:Init( cName )
    ::Name := cName
 RETURN Self

 /////////////////////////////
 //
 CLASS Dog FROM Animal
 //
 /////////////////////////////
    EXPORTED:
    METHOD Talk
 ENDCLASS

 METHOD Dog:Talk()
 RETURN "Bark!"

 /////////////////////////////
  //
  CLASS Cat FROM Animal
  //
  /////////////////////////////
     EXPORTED:
     METHOD Talk
  ENDCLASS

  METHOD Cat:Talk()
  RETURN "Meow!"


Ruby                                                                                                                                 [edit]

  class Animal
    attr_reader :name
    def initialize(name)
      @name = name
    end
    def talk
      raise "Subclass does not implement method"
    end
  end

  class Cat < Animal
    def talk
      "Meow!"
    end
  end

  class Dog < Animal
    def talk
      "Arf! Arf!"
    end
  end

  animals = [Cat.new("Missy"),Cat.new("Mr. Mistoffelees"),Dog.new("Lassie")]
  animals.each{|a| puts a.name + ": " + a.talk}

  #prints:
  #
  #Missy: Meow!
  #Mr. Mistoffelees: Meow!
  #Lassie: Arf! Arf!


Smalltalk                                                                                                                            [edit]

A note that this is a "fileout" of code written inside the Smalltalk environment. People typically do not edit this fileout code, instead
using all the great tools Smalltalk has to offer.

  Object subclass: #Cat
      instanceVariableNames: 'name'
      classVariableNames: ''
      poolDictionaries: ''
      category: 'Pets'!

  !Cat methodsFor: 'accessing' stamp: 'rww 6/23/2010 17:34'!
  name
       "Get the value of name"

      ^ name! !
  !Cat methodsFor: 'accessing' stamp: 'rww 6/23/2010 17:34'!
  name: anObject
        "Set the value of name"

        name := anObject! !

  !Cat methodsFor: 'initialize-release' stamp: 'rww 6/23/2010 17:34'!
  initializeWithName: aName

        self name: aName.! !

  !Cat methodsFor: 'polymorphic' stamp: 'rww 6/23/2010 17:35'!
  talk

        ^ 'Meow!!'! !

  !Cat class methodsFor: 'creation' stamp: 'rww 6/23/2010 17:33'!
  name: aName

        ^ self new
            initializeWithName: aName;
            yourself! !

  Object subclass: #Dog
      instanceVariableNames: 'name'
      classVariableNames: ''
      poolDictionaries: ''
      category: 'Pets'!

  !Dog methodsFor: 'accessing' stamp: 'rww 6/23/2010 17:36'!
  name
       "Get the value of name"

        ^ name! !

  !Dog methodsFor: 'accessing' stamp: 'rww 6/23/2010 17:37'!
  name: anObject
      "Set the value of name"

        name := anObject! !

  !Dog methodsFor: 'initialize-release' stamp: 'rww 6/23/2010 17:36'!
  initializeWithName: aName

        self name: aName.! !

  !Dog methodsFor: 'polymorphic' stamp: 'rww 6/23/2010 17:37'!
  talk

        ^ 'Arf!! Arf!!'! !

  !Dog class methodsFor: 'creation' stamp: 'rww 6/23/2010 17:37'!
  name: aName

      ^ self new
          initializeWithName: aName;
          yourself! !
  | animals |
  animals := {Cat name: 'Missy'. Cat name: 'Mr. Mistoffelees'. Dog name: 'Lassie'}.
  animals do: [:ea | Transcript cr; nextPutAll: ea name, ': ', ea talk; flush].!


Go                                                                                                                                [edit]

Go does not have inheritance, but it still allows for subtype polymorphism through interfaces. Go uses implicit interface
implementation; if a type has the methods listed in the interface's definition than it implements that interface automatically.
  package main

  import(
      "fmt"
  )

  type Animal interface {
      Name() (string)
      Talk() (string)
  }

  type Cat struct {
      name string
  }

  func (c *Cat)Name() (string) {
      return c.name
  }

  func (c *Cat)Talk() (string) {
      return "Meow!"
  }

  type Dog struct {
      name string
  }

  func (d *Dog)Name() (string) {
      return d.name
  }

  func (d *Dog)Talk() (string) {
      return "Woof! Woof!"
  }

  func main() {
      animals := []Animal{
          &Cat{"Missy"},
          &Cat{"Mr. Mistoffelees"},
          &Dog{"Lassie"},
      }

         for _, v := range(animals) {
             fmt.Printf("%v: %v\n", v.Name(), v.Talk())
         }
  }


Parametric Polymorphism                                                                                                        [edit]

      Further information: Parametric polymorphism in type theory and Generic programming for a more general concept
In computer science, the term polymorphism has several different but related meanings; one of these, known as parametric
polymorphism in type system theory and functional programming languages, is known as generic programming in the Object
Oriented Programming Community and is supported by many languages including C++, C# and Java.
Generics allow compile-time type-safety and other benefits and/or disadvantages depending on the language's implementation.
C++ implements parametric polymorphism through templates. The use of templates requires the compiler to generate a separate
instance of the templated class or function for every permutation of type parameters used with it, which can lead to code bloat and
difficulty debugging. A benefit C++ templates have over Java and C# is that they allow for template metaprogramming, which is a
way of pre-evaluating some of the code at compile-time rather than run-time.
Java parametric polymorphism is called generics and implemented through type erasure. This design decision was made to ensure
backwards compatibility and ensure that Java generics are interoperable with non-generic code.
C# parametric polymorphism is called generics and implemented by reification, making C# the only language of the three which
supports parametric polymorphism as a first class member of the language. This design choice is leveraged to provide additional
functionality, such as allowing reflection with preservation of generic types, as well as alleviating some of the limitations of erasure
(such as being unable to create generic arrays). This also means that there is no performance hit from runtime casts and normally
expensive boxing conversions. When primitive and value types are used as generic arguments, they get specialized
implementations, allowing for efficient generic collections and methods

								
To top