Make sure to get the type right!



  • In a C# function with return type "object", I found the following:

     return ((object)(returnValue));
    

    ...rather than

     return returnValue;
    

    Not that the code as written is incorrect, but it has the unfortunate effect of severely eroding any trust that the original coder knows his ass from a hole in the ground.



  • Department of Redudancy Department anybody?



  • @rstinejr said:


    In a C# function with return type "object", I found the following:

     return ((object)(returnValue));
    

    ...rather than

     return returnValue;
    

    Not that the code as written is incorrect, but it has the unfortunate effect of severely eroding any trust that the original coder knows his ass from a hole in the ground.

    The best practise is:

    return returnValue as object;


  • TRWTF is that the method signature declared a primitive return type and not an object... right?



  • @Cassidy said:

    TRWTF is that the method signature declared a primitive return type and not an object... right?

    What?


  • @Sutherlands said:

    @Cassidy said:

    TRWTF is that the method signature declared a primitive return type and not an object... right?

    What?

    I think it's speaking Java.



  • @pkmnfrk said:

    @Sutherlands said:

    @Cassidy said:

    TRWTF is that the method signature declared a primitive return type and not an object... right?

    What?

    I think it's speaking Java.

    I'm unaware of a primitive type in Java named "object"..



  • @morbiuswilters said:

    @pkmnfrk said:
    @Sutherlands said:

    @Cassidy said:

    TRWTF is that the method signature declared a primitive return type and not an object... right?

    What?

    I think it's speaking Java.

    I'm unaware of a primitive type in Java named "object"..

    That's why Cassidy used the conjunction "and not", to clarify that they thought the return type of the method was not one of the object-derived types, but one of the primitive types (int, boolean, etc).

    (The fact that it was spelled out in the OP and commented on by several people that the return type is object, and also this code is C#, is completely beside the point)



  • It was.. another "I've completely missed the point" pisstake.

    But I don't do emoticons.


Log in to reply