Line | |
---|
1 | package testcode;
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Class that refers to itself for the {@link #next()} return type
|
---|
5 | *
|
---|
6 | */
|
---|
7 | public class SelfReference {
|
---|
8 |
|
---|
9 | private Integer num;
|
---|
10 |
|
---|
11 | public SelfReference(Integer n) {
|
---|
12 | this.num = n;
|
---|
13 | }
|
---|
14 |
|
---|
15 | public SelfReference next() {
|
---|
16 | return new SelfReference(num + 1);
|
---|
17 | }
|
---|
18 |
|
---|
19 | @Override
|
---|
20 | public String toString() {
|
---|
21 | return num.toString();
|
---|
22 | }
|
---|
23 |
|
---|
24 | static public void main(String[] args) {
|
---|
25 | // simple print
|
---|
26 | System.out.println(new SelfReference(1).next());
|
---|
27 | }
|
---|
28 |
|
---|
29 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.