[Part 2 - Comparing Java & C#] Generic Types

The most common use of generic types is to create collection classes. There are some ones in c# such as list, hasttable, dictionary, array...

I have seen no diffirence between C# and Java as the following java example:

import java.util.*;
import java.io.*;

class pairtest1
{
    public static ArrayList<String> a=new ArrayList<String>();
    
 public static void main(String[] args)
 {
   Pair<String> mystring=new Pair<String>("Great");
  
  
 }
}

 class Pair<T>
{
  T myvalue;
  Pair(T in_value)
  {
    myvalue=in_value;
    System.out.println("Pair inited type:" + myvalue);
  }
 
 
}
Share on Google Plus

About Chien

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Post a Comment