Q:

Incompatible types generics Java

I did this code:
import java.util. LinkedList;

public class Node<T> {
private T data;
private LinkedList<T> children;
public Node(T data) {
    this.data = data;
    this.children = new LinkedList<T>();
}
public T getData() {
    return this.data;
}
public LinkedList<T> getChildren(){
    return this.children;
}
}

public class Graph <T> implements Network<T> {
private Node source;
private Node target;
private ArrayList<Node> nodes = new ArrayList<Node>();

public Graph(T source,T target) {
    this.source = new Node(source);
    this.target = new Node(target);

}

public T source() {
    return source.getData();
}

public T target() {
    return target.getData();
}

I get this error on source() and target(): required T found java.lang. Object why?  the type of return of getData() function it's T(generic type of return)

A:

private Node source;
private Node target;

These should be Node<T>.  Likewise on a few of the following lines.  The compiler will have given you a warning.  Take note of it. ( When you mix raw types and generics, the Java Language Spec often requires the compiler to give up.)