summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing1006.java
blob: 01fabbf946ceb669dc6585e309ebbfd81fb4ba12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Listing1006.java */

class IntWrapper
{
  public int value;

  public IntWrapper(int value)
  {
    this.value = value;
  }
}

public class Listing1006
{
  public static void inc1(IntWrapper w)
  {
    ++w.value;
  }

  public static void inc2(int[] i)
  {
    ++i[0];
  }

  public static void main(String[] args)
  {
    //Variante 1: �bergabe in einem ver�nderlichen Wrapper
    IntWrapper i = new IntWrapper(10);
    System.out.println("i = " + i.value);
    inc1(i);
    System.out.println("i = " + i.value);
    //Variante 2: �bergabe als Array-Element
    int[] j = new int[] {10};
    System.out.println("j = " + j[0]);
    inc2(j);
    System.out.println("j = " + j[0]);
  }
}