Notices
Results 1 to 3 of 3

Thread: java question

  1. #1 java question 
    Forum Junior
    Join Date
    Jun 2006
    Posts
    264
    Hey, I'm basically just look for some terminology here... I have run into a piece of code that I am not sure what it is. I was wondering if anyone could tell me what it is called so that I could look it up in my textbook or on the internet to find out more about it.

    It is in a interface declaration:
    Code:
    public interface Grid<E>
    Later this interface is used here:
    Code:
    private Grid<Actor> grid;
    The part that I am a little lost on is the part with the "<>". If anyone could tell me what this is called that would be great.

    Thanks,
    Shawn


    Reply With Quote  
     

  2.  
     

  3. #2  
    New Member
    Join Date
    Sep 2008
    Posts
    1
    public interface Grid<E>
    declaration of a generic class which takes type as specified in <>

    public class Actor
    {
    private String fName,lName;
    public Actor(){}
    }

    private Grid<Actor> grid;
    it is declaring a variable called grid of Grid class which strictly takes Actor type.
    ..

    hope that helps ....
    tried my best


    Reply With Quote  
     

  4. #3  
    New Member
    Join Date
    Oct 2008
    Posts
    1
    Hi,

    Sun have a little tutorial on generics, basically you're parameterising a class by type.

    You've probably seen them in the API - for example the ArrayList<E> in java.util. In that case it lets you define lists of different types, e.g.

    Code:
    ArrayList<String> stringList = new ArrayList<String>();    // list of Strings
    ArrayList<Integer> intList = new ArrayList<Integer>();     // list of Integers
    
    stringList.add("A word");
    intList.add(new Integer(3));        // both ok
    
    stringList.add(new Integer(5));     // this would fail (wrong type)
    Your Grid<E> would work in a similar way.
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •