Results 1 to 17 of 17
  1. #1
    javanewbie83 is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Default Passing short value as parameter

    Hi every1,

    i have a function that accepts short as an argument:

    failedcount (short responcode){

    switch(responcecode){
    case 1:

    case 2:

    case 3:
    }

    }


    now i have a method that calls it:

    create {

    failedcount(3) --- here it says can't pass an int value

    }

    so if i do:
    short abc = 3;
    and then do failedcount (abc);

    Thank you..

  2. #2
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    are you saying if you do
    short abc = 3;
    failedcount(abc);
    it still doesnt work?

  3. #3
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    Try converting abc into short datatype before sending it to failedcount();
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JT4NK3D View Post
    are you saying if you do
    short abc = 3;
    failedcount(abc);
    it still doesnt work?
    No he worried about that difference there. He can't directly pass a value, and he wants to so it. Don't like to use extra lines there.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    thats the convertion i was talking about. =) Thats the simpliest answer. =) Im just wandering, why use short data type where you can use a int?
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  8. #8
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    ^_^ I guess i can't argue with that. Please mark this thread [SOLVED] if we satisfied your question. =P
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  10. #10
    ferranb is offline Member
    Join Date
    Jun 2008
    Posts
    22
    Rep Power
    0

    Default

    A little offtopic, but take care about forgetting to use break statements on the case conditions.

    Ferran

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    That's depend on the implementations take place. In some cases need to have more than one case statements execute at a time.

  12. #12
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default misplaced break

    Quote Originally Posted by Eranga View Post
    That's depend on the implementations take place. In some cases need to have more than one case statements execute at a time.
    I wonder sometimes if the misplaced break in the 1-800 incident was someone placing a break where original code relied on simple jump-table into the switch. Sort of like (?:(?:)) which can be either a tool or a tarantula.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually using large number of case statements is bad practice, I think. I've never comes with such a situation more that 10 cases in a single application. But I've found someones code which have 30 cases, and that's the longest I've seen so far.

  14. #14
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default yep, about thirty in a switch

    Quote Originally Posted by Eranga View Post
    Actually using large number of case statements is bad practice,
    In general, yes. Especially when we get code like:
    Java Code:
    failedcount(3) // here it says can't pass an int value
    but in my opinion building a lib that takes a list from a file ( or ram resident Collection ) and writes to a CharArrayOutputStream (${title}) would be of utility in acheiving the ability to build large switches.
    Quote Originally Posted by Eranga View Post
    I think. I've never comes with such a situation more that 10 cases in a single application. But I've found someones code which have 30 cases, and that's the longest I've seen so far.
    That's about the max that I could maintain by hand, an automated tool would be needful at that point.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Nicholas Jordan View Post
    my opinion building a lib that takes a list from a file ( or ram resident Collection ) and writes to a CharArrayOutputStream (${title}) would be of utility in acheiving the ability to build large switches.
    I agreed with you. I gave the same advice to one my friends to use large switches in one of his application. He says it's fine. Even I'm not use of it, seems to me that's the best way. Actually what I believe is working with streams in much easier, much safer.

    Quote Originally Posted by Nicholas Jordan View Post
    That's about the max that I could maintain by hand, an automated tool would be needful at that point.
    DO you know any such methodology I can use in such instances?

  16. #16
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Lightbulb lets build one

    Quote Originally Posted by Eranga View Post
    DO you know any such methodology I can use in such instances?
    It's early AM, still not awake yet, but I know from field experience that we are gonna recursively descend on Data Definitions, Type Definitions and Goal Definitions. What we will end up with is a TreeListControl, but we could have the rh view be a list of statements and the left-pane be the switch vals ( iow case n : ) the rh display would be what goes inside {}

    We would need a prototype problem domain to do inital design concepting.

    Creative Commons lic. Root word of license is lice. People who make license necessary won't bother to read the license. CC has accomplished a great and remarkable thawing of The Glacial Pace of Law. ( nomeclature from their field )
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Input parameter of Main method
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 07-12-2008, 06:24 PM
  2. Replies: 1
    Last Post: 05-08-2008, 09:38 AM
  3. why doesn't this short applet work?
    By kim85 in forum New To Java
    Replies: 1
    Last Post: 01-20-2008, 08:43 PM
  4. arugment/parameter
    By ravian in forum New To Java
    Replies: 5
    Last Post: 01-04-2008, 09:43 AM
  5. Short/Integer
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-06-2007, 09:28 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
  •