w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Java: how to make a method return an array of classes

You need to properly create the array:

return new Class<?>[]{classA.class, classB.class,

What you're trying to do only works in with array declarations:

Class<?>[] classes = {classA.class, classB.class,
classC.class};  // <--
return classes;

Array creation expressions are detailed in JLS ยง15.10.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.