Results 1 to 14 of 14

Thread: List

  1. #1
    java4amanda is offline Member
    Join Date
    Jan 2012
    Posts
    55
    Rep Power
    0

    Default List

    Hi all,


    I was going through an article on list and i bumped on this line of code >>> List l = new ArrayList<Integer>(); , and when i tried running that code i get this error " incompatible type." Any idea??

    Regards,
    Shishir

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: List

    You probably imported the wrong class.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: List

    Quote Originally Posted by java4amanda View Post
    Hi all,


    I was going through an article on list and i bumped on this line of code >>> List l = new ArrayList<Integer>(); , and when i tried running that code i get this error " incompatible type." Any idea??
    That line is trying to assign a generic List<String> to a 'raw' list; the compiler warns against it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    java4amanda is offline Member
    Join Date
    Jan 2012
    Posts
    55
    Rep Power
    0

    Default Re: List

    no i used import java.util.*;

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: List

    If you are getting an "incompatible types" error on that line then the compiler is finding another List or ArrayList class in your classpath.
    It is either a class you have created or one you have imported.

    The only thing (assuming you do not have any extraneous List/ArrayList classes lying around) you should get from that line is a generics warning.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    java4amanda is offline Member
    Join Date
    Jan 2012
    Posts
    55
    Rep Power
    0

    Default Re: List

    thanks!!

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: List

    And the solution was?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: List

    The solution was: take what you can get from a forum, never give anything back.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: List

    Quote Originally Posted by DarrylBurke View Post
    The solution was: take what you can get from a forum, never give anything back.
    Here are some more tips:

    1) Crosspost as much as possible but don't tell anyone; posting is like fishing: the more bait you throw in the more answers you'll get.
    2) Use txt speak or even better: combine it with sms speak; people don't like to read complete words.
    3) Don't post your code and if you do, make sure it's uncompilable and don't add any code tags; if it were hard to write it should be hard to read.
    4) Add as many links to vague sites as possible; it makes people curious.
    5) Include the original assignment text as .pdf files.
    6) Bump your thread every fifteen minutes or so; that'll wake up the lazy moderators.
    7) Don't thank anyone for their answers; it's their duty to supply answers.
    8) It's best to add your question to an old, long dead thread. New threads are expensive.
    9) Supply your own interpretation to compilation errors (e.g. "the damn thing threw some stupid error at me"); the original messages as too vague.
    10) Always use lower case letters in posts and no punctuation. If possible (not always) leave in some spelling mistakes because we all know how hard it is to double check your own posts.


    kind regards,

    Jos ;-)
    Last edited by JosAH; 05-17-2012 at 02:15 PM.
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: List

    lol

    10) Always use lower case letters in posts and no punctuation. If possible (not always) leave in some spelling mistakes because we all know how hard it is to double check your own posts.

    Best Regards

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

    Default Re: List

    Quote Originally Posted by lannie1980 View Post
    lol

    10) Always use lower case letters in posts and no punctuation. If possible (not always) leave in some spelling mistakes because we all know how hard it is to double check your own posts.

    Best Regards
    Very good; I added it to the list; maybe we can make it the canonical list of forum poster tips ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: List

    3) Don't post your code and if you do, don't add any code tags; if it were hard to write it should be hard to read.
    3) Don't post your code and if you do, make sure it's uncompilable and don't add any code tags; if it were hard to write it should be hard to read.

    Added a phrase.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: List

    Quote Originally Posted by DarrylBurke View Post
    3) Don't post your code and if you do, make sure it's uncompilable and don't add any code tags; if it were hard to write it should be hard to read.
    Added a phrase.
    Also a very good addition (added to the list).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 03-25-2012, 09:25 PM
  2. Replies: 8
    Last Post: 11-04-2011, 08:30 PM
  3. Linked List, Array List time complexity
    By Rick99771977 in forum New To Java
    Replies: 4
    Last Post: 08-18-2011, 05:37 AM
  4. Replies: 2
    Last Post: 11-22-2009, 05:24 PM
  5. Replies: 3
    Last Post: 11-21-2009, 05:48 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
  •