I am having trouble with making part of my code to work. The error says "Cannot resolve symbol ‘asList’ and "Cannot resolve symbol ‘info’"
One solution I found was to put this code in
public static void main(String[] args) {
and it would work, but I do not know why that is the case.
package com.solvd.army.lambda;
import com.solvd.army.Runner;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Arrays;
public class PrintRanks {
private static Logger logger = LogManager.getLogger(Runner.class.getName());
String ranks[] = {"General", "Colonel", "General", "IntelligenceTeam", "Lieutenant", "Major", "Doctor",
"Nurse", "Operator", "Sergeant", "Soldiers"};
Arrays.asList(ranks).forEach((ranks) -> logger.info(ranks));
}
>Solution :
Your statement should be inside a method.
e.g.
public void display(){
Arrays.asList(this.ranks).forEach((ranks) -> logger.info(ranks))
}
And then you can call this method (may-be inside the main method?)