Я постоянно поймаю NoSuchMethodException TypesForSets$SetType.<init>(int)
во время попыток связаться с конструктором вложенного класса. У меня есть код:Отражение во вложенных классах
public class TypesForSets {
static <T> Set<T> fill(Set<T> set, Class<T> type) {
try {
for (int i = 0; i < 10; i++)
set.add(type.getConstructor(int.class).newInstance(i));
} catch (Exception e) {
throw new RuntimeException(e);
}
return set;
}
static <T> void test(Set<T> set, Class<T> type) {
fill(set, type);
}
public static void main(String[] args) {
test(new HashSet<SetType>(), SetType.class);
}
class SetType {
int i;
public SetType(int n) {
i = n;
}
}
}
Когда я помещал SetType
отдельно как общественный класс она работает просто отлично.