• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Class Function Question

JC0724

Weaksauce
Joined
Oct 11, 2008
Messages
105
This is for Java

I am just trying to double check if this is the correct way to create a function for a class and return that type.

//this is inside of the another class or Object2
public Object1 functionName(Object1 variable1) {

//Do I even need to do this below? Cause I am passing it in as a parameter
Object1 variable = new Oject1();


//code in here

return variable1; //returning Object1 variable1
}
 
public Object1 functionName(Object1 variable1) {
You don't necessarily need to pass in an argument. It depends on what your function needs to do. But it rarely makes sense to return this argument (since the caller already has it). You probably want to return the local variable instead.

P.S.: Class functions are something different. This is an instance function.

P.P.S.: Use
Code:
 tags next time.
 
[CODE] Code goes in here [/CODE]

Code:
//this is inside of the another class or Object2
public Object1 functionName(Object1 variable1)
{
    //Do I even need to do this below? Cause I am passing it in as a parameter
    Object1 variable = new Object1();

    //code in here

    return variable1; //returning Object1 variable1
}

Preserves indentation, and uses a monospaced font.
 
Back
Top