I am trying some code but I cannot compile it. is there any error? I have attached the code below.
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
public class Node
{
private int nodeId;
private List<Connection> outboundConnections = new ArrayList<>();
public Node(int nodeId)
{
this.nodeId = nodeId;
}
public void addConnection(Connection connection)
{
this.outboundConnections.add(connection);
}
}
and when i compile, i got this kind of error :
Node.java:9: error: cannot find symbol
private List<Connection> outboundConnections = new ArrayList<>();
^
symbol: class Connection
location: class Node
Node.java:16: error: cannot find symbol
public void addConnection(Connection connection)
^
symbol: class Connection
location: class Node
Node.java:9: error: unexpected type
private List<Connection> outboundConnections = new ArrayList<>();
^
required: class
found: <E>ArrayList<E>
where E is a type-variable:
E extends Object declared in class ArrayList
3 errors
is only valid on Java 7+. If you run Java 6 or earlier, you need to use: