Код, написанный мной, который не принимает валидатор:
public class Solution {
static int count = 15;
static volatile int createdThreadCount;
public static void main(String[] args) {
System.out.println(new GenerateThread());
}
public static class GenerateThread extends Thread {
public GenerateThread(){
super(String.valueOf(++createdThreadCount)); //Вызвать конструктор суперкласса с параметром String - номером созданной нити.
start();
}
public void run(){
if (createdThreadCount < count){
System.out.println(new GenerateThread());
}
}
@Override
public String toString(){
return currentThread().getName() + " created";
}
}
}
Код, который я тупо скопировал, чтобы пройти проверку:
public class Solution {
static int count = 15;
static volatile int createdThreadCount;
public static void main(String[] args) {
System.out.println(new GenerateThread());
}
public static class GenerateThread extends Thread {
public GenerateThread() {
super(((Integer) (++createdThreadCount)).toString());
start();
}
public void run() {
if (createdThreadCount < count ) {
GenerateThread generateThread = new GenerateThread();
System.out.println(generateThread);
}
}
@Override
public String toString() {
return this.getName() + " created";
}
}
}
Собственно, в чём принципиальная разница, если работают они одинаково (в IDEA уж точно)?