Issue
I am having a lot of trouble with putting an array as a parameter in one of my REST API methods. My server will be retrieving data from a separate API which requires all the below fields to be set.
public class Article {
private String by;
private int descendants;
private int[] kids;
private int id;
private int score;
private int time;
private String title;
private String type;
private String url;
In another class, I have the following method:
@Override
public List<Article> selectAllArticles() {
//TODO: argument fix needed
return List.of(new Article("by", "descendants", [???], "id", "score", "title", "type", "url"));
}
The [???] is where I'm trying to figure out how to write out the array.
Solution
You can either return an array:
public Object[] selectAllArticles() {
return new Object[] {"by", "descendants", [???], "id", "score", "title", "type", "url"};
}
or if you really need specific type you don't need a List<?> of length 1, simply return the Article:
public Article selectAllArticles() {
return new Article("by", "descendants", [???], "id", "score", "title", "type", "url");
}
I also want to note that [???] is not a thing in Java
Answered By - Player_X_YT
Answer Checked By - Marilyn (JavaFixing Volunteer)