Image

pointers in Java

So, why do they say there are no pointers in Java?


package theory;

public class Pointer {
  public Object to = null;

  public Pointer() {
  }

  public Pointer(Object to) {
    set(to);
  }
  
  public void set(Object to) {
    this.to = to;
  }
  
  public Object get() {
    return to;
  }
  
  public Object deref() {
    return get();
  }

  public String toString() {
    return super.toString() + "->" + to;
  }

  public static void main(String[] argv) {
    Pointer p1 = new Pointer();
    String s = "a string";
    Pointer p2 = new Pointer(s);
    p1.set(p2);
    System.out.println(p1);
  }
}