When I try to use methods inside a class in which I extend Thread it does not receive the methods after the run.
My class:
public class PassPhraseValidator<E> extends Thread { private List<E> list; private boolean isValid; private String passPhrase; public PassPhraseValidator(List<E> list) { this.list = list; } public String getPassPhrase() { return passPhrase; } public boolean isValid() { return isValid; } public void run(){ this.passPhrase = Arrays.toString(list.toArray()); this.isValid = list.stream().filter(e -> Collections.frequency(list, e) > 1).count() == 0; } } So when I execute this class like this:
PassPhraseValidator<Integer> validIntegerPassPhrase = new PassPhraseValidator<>(Arrays.asList(12, 18, 15, 32)); validIntegerPassPhrase.start(); System.out.println(validIntegerPassPhrase.getPassPhrase() + " valid: " + validIntegerPassPhrase.isValid()); It gives me false while it should be true because the run function wasn't ran yet.
What am I doing wrong here? How can I make multithreading part of this? It does work when I directly put it inside the methods.