Results 1 to 6 of 6
  1. #1
    dushmantha.e is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Smile Arrowhead brackets

    I don't understand the usage of arrowhead brackets in java..

    ex- List<Book> b=new ArrayList<Book>();

    here Book is a class name...i'm new to this...please help:).

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dushmantha.e View Post
    I don't understand the usage of arrowhead brackets in java..

    ex- List<Book> b=new ArrayList<Book>();

    here Book is a class name...i'm new to this...please help:).
    That is an example of Java Generics. It helps the programmer in compile time type safety (C++ has a similar looking feature 'class templates' but both are entirely different mechanisms).

    kind regards,

    Jos

  3. #3
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Well, aside from the typical less than (<) and greater than(>) operations, it is generics. A generic argument is used to create classes that provide functionality for any objects or for any objects derived from a specific type. They are similar to C++ class templates, but while C++ creates completely separate classes for each generic/template argument used, Java does not - which means that you cannot create arrays of the generic argument, or cast anything to the generic argument type.

    A full tutorial is here - Java Generics
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    List<Book> b=new ArrayList<Book>();

    This is read "list of books b is a new array list of books".

    Generics is the ability to have lists (/maps/sets etc) of something. You use a line like the one to posted to declare and create them. And the compiler will complain if you try and use a member of the list as anything but a reference to a Book instance.

  5. #5
    dushmantha.e is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default Thanks

    Thanks JosAH, it was helpfull:)

  6. #6
    dushmantha.e is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default Thanks

    Thank you so much everybody sorry i so your replies now.:)

Similar Threads

  1. Bracket help - can't find the missing brackets.
    By Z E P H Y R in forum New To Java
    Replies: 0
    Last Post: 03-17-2009, 10:26 PM

Posting Permissions

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