Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to create a generic class

Java: How to create a generic class
{filelink=12229}

public class Generic_Class  // Definition of a generic class
 {
  T obj; // Declare an object of type T
  Generic_Class(T obj)
  {
    this.obj = obj;
  }
  T get_objet()
  {
    return obj;
  }
  // Displays the type of the object
  void show_TypeObjet()
  {
    System.out.println("The type of the object: " + obj.getClass().getName());
  }
}
 class Test
{
  public static void main(String args[])
  	{
    Generic_Class obj_str;
    obj_str = new Generic_Class("Welcom");
    obj_str.show_TypeObjet();
    System.out.println("value: " + obj_str.get_objet());
  }
}

Users who found this page were searching for:

  • java CRC32
  • java elapsed time in seconds
  • remove one entry from dictionary python
  • python if key exists
  • java date get number of day of current month

No comments yet.

Leave a Comment