juan_gandhi: (Default)
[personal profile] juan_gandhi
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);
  }
}

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
181920 21 222324
25 262728 2930 31

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 1st, 2025 03:00 am
Powered by Dreamwidth Studios