Classe subcontrole:
package br.com.alura.alurator.playground.controle;
public class SubControle extends Controle {
public SubControle() {}
private SubControle(String s) {}
}
Class Controle:
package br.com.alura.alurator.playground.controle;
import java.util.List;
public class Controle {
private List<String> lista = List.of("item 1", "item 2", "item 3");
public Controle() {}
public Controle(String s) {}
private Controle(String s, String t) {}
public List<String> getLista() {
return lista;
}
}
package br.com.alura.alurator.playground.reflexao;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import br.com.alura.alurator.playground.controle.SubControle;
public class TesteInstanciaObjetoCorretamente {
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Class<SubControle> subControleClass1 = SubControle.class;
Class<?> subControleClass2 = Class.forName("br.com.alura.alurator.playground.controle.SubControle");
Class<?> controleClass1 = Class.forName("br.com.alura.alurator.playground.controle.Controle");
Constructor<SubControle> constructor = subControleClass1.getDeclaredConstructor(String.class);
System.out.println(constructor);
constructor.setAccessible(true);
Object subControle = constructor.newInstance();
System.out.println(subControle);
}
}
Gostaria de entender porque o meu código está identico ao da aula e mesmo assim lança Exceção de IllegalArgument na linha onde invoco o newInstance().