Results 1 to 6 of 6

Thread: Java - question on enum

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Java - question on enum

    Hello,
    I am new to java and I have just started to coding in java. What this means:
    My first question is
    Code:
    enum Horse
    What does the word reserved enum?

    Second question
    What this means:
    Code:
    Map mp = <string,string> new TreeMap <string,string>();
    That means <string,string> ? In fact, it means <> ?
    Any help on these topics will be appreciated. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Java - question on enum

    Hello,
    Generics is simple, it's just that instead of defining a TreeMap which contains Objects, you specify the type of attributes TreeMap (String here). Instead of declaring new TreeMap (), you declare new TreeMap <string,string> to say that you'll use in your String TreeMap, that's all. If you need more informational on this then you can visit the sun's official site and there you can find more detailed information on this.

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: Java - question on enum

    Hello,
    The letters E and T or represent other classes that you defined it? is an unknown class.
    For example the ArrayList class:
    Code:
    ArrayList <E>
    When you created an ArrayList like:
    Code:
    List mlst = new ArrayList <String> ();
    E is used becomes the object in the String class.
    I hope you are understanding what I am trying to explain to you. I recommend you to read some basics of java that it the Java core syllabus, so that you can understand what is being explained.

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Java - question on enum

    Hello,
    Just have a look at the following
    Code:
    addAll(Collection <? Extends E> c)
    As E is a String, it means that the method accepts any type of collection that contains objects that inherit from String. The String is a bad example since you can not extend. In a Map you not only the class of objects but also the keys, have you:
    Code:
    Map <K,V>
    And then the letters K and V are used as the E of the List.

  5. #5
    Join Date
    Nov 2009
    Posts
    446

    Re: Java - question on enum

    Hello,
    Have a look at the following syntax
    Code:
    <?>
    is primarily used as part of an interface. You can also define an interface taking or returning a collection whose type is defined by the class implements. This is very useful
    Code:
    <E>
    is often used to refer to the word Element, i.e one can do everything and anything to its code by using this.

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Java - question on enum

    Hello,
    I will try to explain you the following
    Code:
    <E>
    is often used to refer to the word Element, i.e a it can do everything and anything.
    For Map is similar:
    Code:
    K -> Key
    V -> Value
    If you need any more information regarding this topic then feel free to post and we will try to help you from this.

Similar Threads

  1. Basic Java question
    By colby02184 in forum Software Development
    Replies: 2
    Last Post: 11-11-2011, 05:08 PM
  2. UML to Java question
    By imgr8 in forum Software Development
    Replies: 1
    Last Post: 20-04-2010, 01:05 PM
  3. Which java enum should I give to the variable "followers"?
    By KADRI in forum Software Development
    Replies: 4
    Last Post: 20-02-2010, 06:24 PM
  4. Java program to use enum in switch statement.
    By MADGE25 in forum Software Development
    Replies: 5
    Last Post: 01-02-2010, 06:12 PM
  5. Java math question
    By Daren in forum Software Development
    Replies: 2
    Last Post: 02-09-2009, 06:33 PM

Tags for this Thread

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
  •  
Page generated in 1,751,608,597.22909 seconds with 16 queries