I have a java file which contains a list of contents that I'm looking to import statically into another file.
However, I am running into an error that the compiler "cannot find symbol".
Visual code has also highlighted the code with the error:
Syntax error, static imports are only available if source level is 1.5 or greater.
I followed the syntax from this post.
Constants.java
public final class Constants{
private Constants(){} //Private constructor - no instantiation or subclassing.
// The first two members are constants, used to configure the simulator.
public static final int MAX_NUMBER_OF_EVENTS = 100; // Maximum number of events
public static final double SERVICE_TIME = 1.0; // Time spent serving a customer
public static final int CUSTOMER_ARRIVE = 1;
public static final int CUSTOMER_DONE = 2;
}
Simulator.java
import static Constants.*; //doesn't work.
public class Simulator{
private Event[] events = new Event[MAX_NUMBER_OF_EVENTS]; //Array to queue events - order of events not guaranteed.
//numOfEvents keeps track of number of events in the array.
//total* variables used to track simulation.
//*Id variables used to identify customer.
private int numOfEvents, totalNumOfServedCustomer, totalNumOfLostCustomer = 0;
private int lastCustomerId = 0;
private int servedCustomerId, waitingCustomerId = -1;
//booleans used to track customer status i.e. served or waiting.
private boolean customerBeingServed, customerWaiting = false;
//doubles used to keep track of time of total simulation and waiting time.
private double timeStartedWaiting, totalWaitingTime = 0;
...
}
I'm running Visual Code with Red hat's language support for Java on JDK 9.