#Can't give arguments to a method.

27 messages · Page 1 of 1 (latest)

cursive owl
#

So I have a variable I want to give as the argument of my method. It goes as follow:

public void method1() {
  List<Vertex> MSTGraph = ...; // actual code for this but isn't relevant
  System.out.println("VERTICES EDGES LIST #0");
  for (Vertex vertex : MSTGraph) {
      ArrayList<String> connectedVerticesLabels = new ArrayList<>();
      for (Vertex vertexEdge : vertex.getEdges().keySet()) {
          connectedVerticesLabels.add(vertexEdge.getLabel());
      }
      System.out.println("Vertex #" + vertex.getLabel() + " " + connectedVerticesLabels);
  }
  method(MSTGraph)
}


public List<Vertex> method(List<Vertex input) {
    System.out.println("VERTICES EDGES LIST");
    for (Vertex vertex : MST) {
        ArrayList<String> connectedVerticesLabels = new ArrayList<>();
        for (Vertex vertexEdge : vertex.getEdges().keySet()) {
            connectedVerticesLabels.add(vertexEdge.getLabel());
        }
        System.out.println("Vertex #" + vertex.getLabel() + " " + connectedVerticesLabels);
    }
}

Here are the outputs:

elfin obsidianBOT
#

This post has been reserved for your question.

Hey @cursive owl! 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.

cursive owl
#

actual screenshots of the code if you want:

rose plank
#

what/where's the actual issue here

cursive owl
#

the output is different

#

Both methods should return exactly the same thing since they have the same code and the same variable to work with

#

but for some reason it doesn't

rose plank
#

how do you know it's the same list to work with

#

oh wait i was gonna suggest adding a method call but i just noticed that lmao

cursive owl
#

Why would it be different?
I do nothing to change it in this part of the code

rose plank
#

blind on mobile moment

cursive owl
#

😎

rose plank
#

ah wait

#

you aren't using the same list

cursive owl
#

just tried that and still doesn't work

rose plank
#

you're using MST instead of the passed input

#

in the loop

cursive owl
rose plank
#

it isn't though?

cursive owl
#

the method getPerfectMatching() does change the mst

#

maybe that's the issue (though I doubt it because when passing a variable isn't it creating a new instance of it?)

#

didn't work

cursive owl
#

UPDATE:
by change the second argument to simply input instead of getPerfectMatching(MSTGraph)
I don't have the error

#

So yeah I just need to clone it