Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Tolls

Thread: What is this?

  1. #1
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    63
    Rep Power
    0

    Default What is this?

    It's been a year since I did java. I was wondering what this was? I remember doing this a year ago in my csci class. All i think I know is that this statement creates a new Bag object which is being referenced by by shoppingCart. BagInterface is the interface which contains a bunch of specific methods. Why is there <Item>, what is happening there? It's highlighted in yellow. Specifically what is that called? So I can look it up on youtube. Thanks!
    Attached Thumbnails Attached Thumbnails What is this?-photo-oct-18-5-18-32-pm.jpeg  

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: What is this?

    You've been here long enough to know how to post code in code tags. Please edit your post and replace the screenshot with the code. Thank you.

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

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: What is this?

    Yeah. But I have to say I it would not have occurred to me to print out decimal dollars and cents the way he did.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: What is this?

    Quote Originally Posted by jim829 View Post
    Yeah. But I have to say I it would not have occurred to me to print out decimal dollars and cents the way he did.
    Fair enough, seeing as how 105 would end up as #1.5.

    This is from my personal archives :)
    Java Code:
      public static String formatAsRupees(int paise) {
        return paise < 10 ? "0.0" + paise
            : paise < 100 ? "0." + paise
                : String.valueOf(paise).replaceAll("\\d\\d$", ".$0");
      }
    Note to any reader who doesn't use regexes: the $ symbols in that code are not the unit of American (and other) currency.

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

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: What is this?

    Shouldn't that constructor be: 'new Bag<Item>()'? Or is it some new Java 8 frilly-willy-nilly again? ;-)

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: What is this?

    Quote Originally Posted by JosAH View Post
    Shouldn't that constructor be: 'new Bag<Item>()'? Or is it some new Java 8 frilly-willy-nilly again? ;-)

    kind regards,

    Jos
    Actually, that's the Java 7 diamond notation. The type is inferred from the left hand side (except when you use anonymous classes. Then you need to specify the type on the right hand side). You can still do it your way. Eclipse will flag it as redundant. Not certain about other IDE's.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: What is this?

    Quote Originally Posted by JosAH View Post
    Shouldn't that constructor be: 'new Bag<Item>()'? Or is it some new Java 8 frilly-willy-nilly again? ;-)

    kind regards,

    Jos
    Quote Originally Posted by jim829 View Post
    Actually, that's the Java 7 diamond notation.
    Yeah, get with the times, Daddy-oh...that's so 2011!
    ;)
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: What is this?

    Duh, lemme tell you this sony: in my days (when everything was better) we didn't have no generics; in fact they were illegal and all classes were made of wood; nowadays all them classes are decorated with those frillies; they are just faggot classes I'm telling you ...

    kind regards,

    Jos (Fortran didn't have all that humbug either; and was Fortran a bad thing? And all them punched cards? No sirrree)
    Build a wall around Donald Trump; I'll pay for it.

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: What is this?

    Quote Originally Posted by jim829 View Post
    You can still do it your way. Eclipse will flag it as redundant.
    I haven't seen that happen out of the box, perhaps in Eclipse Mars (haven't upgraded yet, I always wait for SR1)?

    Netbeans 8 most definitely complains about it by default. IMO that is a little too invasive, there is nothing actually wrong or can go wrong with the code.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Posting Permissions

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