Forum Stats

  • 3,839,864 Users
  • 2,262,546 Discussions
  • 7,901,086 Comments

Discussions

Static Tuples in java ?

docesam
docesam Member Posts: 6
edited Aug 26, 2015 2:35PM in New To Java

coming from C# (sorry to offend you) where i am able make a method like this:

Tuple<string,int,int,bool> MyMethod(string name ,int accessLevel)

{

    //do stuff

}

Tuple<string,int,int,bool> is static and i can alter the <string,int,int,bool> as much as i wish. the primary advantage of the "Tuples" thing is to avoid writing value objects , because with complex programs value objects can grow out of control and make changes to programs lengthy and time consuming adding insult to injury. if i am to write a value object i don't need tuples , a regular class will do.

what is the equivalent of (static) C# tuples in java? because i searched i couldn't find the term for that.

Answers

  • Unknown
    edited Aug 26, 2015 1:21PM
    docesam wrote:
    
    coming from C# (sorry to offend you) where i am able make a method like this:
    
    Tuple<string,int,int,bool> MyMethod(string name ,int accessLevel)
    {
    
        //do stuff
    }
    
    Tuple<string,int,int,bool> is static and i can alter the <string,int,int,bool> as much as i wish. the primary advantage of the "Tuples" thing is to avoid writing value objects , because with complex programs value objects can grow out of control and make changes to programs lengthy and time consuming adding insult to injury. if i am to write a value object i don't need tuples , a regular class will do.
    
    what is the equivalent of (static) C# tuples in java? because i searched i couldn't find the term for that.
    
    

    There is no equivalent in Java for using a tuple for the return value.

    This article shows how you might mimic that behaviour.

    https://dzone.com/articles/whats-wrong-java-8-part-v

    The first time a programmer is missing tuples is often when he feels the need to return multiple values from a method. As we all know, Java methods may take as many arguments as needed, but they can only return a single value.
    
  • docesam
    docesam Member Posts: 6
    edited Aug 26, 2015 2:35PM

    thank you for you answer.

    do you know of any reason why this is not implemented ? because in a single day this feature alone can probably save millions of key presses , a few sane brains and a suicide.

    B.S. :you are level 18 i am level 1 ,it seems like playing World of Warcraft !!

This discussion has been closed.