#Follow up question to the (assign new variable through a method) question

19 messages · Page 1 of 1 (latest)

mortal wind
#
assign: to initialize a new variable and assign a value to it. Example: assign
x y, where x is the variable and y is the value assigned. The value could be
an integer number, or a string

Here is what I got answered with on this form

public void assign(String varType, String varName, Object value) {
    if (varType.equals("int")) {
        int varName = (int) value;
    } else if (varType.equals("String")) {
        String varName = (String) value;
    }
}

here is the issue

varName is already declared in the scope.
abstract sluiceBOT
#

This post has been reserved for your question.

Hey @mortal wind! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

wind marsh
#

fix that!

mortal wind
#

How are they both being used for that?

#

Int varName = (int) value;

#

value is the value of the integer named the input in varName

wind marsh
#

int varName = (int) value;

#

??

#

and in if statement

#

String varName = (String) value;

#

??

mortal wind
#

Okay but thats what i want, and only one of them will execute not both.

#

The logic is right i just still don’t understand why it wont work

wind marsh
#

huh?

mortal wind
#

Okay i will!

mortal wind
#

Thread is still open if anyone can help😁