public static int methode1() {
methode2();
return Thread.currentThread().getStackTrace()[2].getLineNumber();
}
Wie die Überschrift schon sagt, verstehe ich nicht warum ich an den Stellen eine 2 eintragen musste. Ich habe die Aufgabe mit einer 1 ausgeführt und nicht bestanden. Mit zweien ging es dann.
Vielen Dank im vorraus für etwaige Erklärungen.
Warum muss ich an der stelle im Code eine 2 benutzen?
In der Diskussion
Kommentare (1)
- Beliebt
- Neu
- Alt
Du musst angemeldet sein, um einen Kommentar schreiben zu können
Gellert Varga
22 Juli 2020, 23:15
Put this code:
into the method(1), before the 'return' command.
Plus write before the program:
And try the program, and observe the output!
The first item of the array (on index 0): the getStackTrace() method itself.
The second item of the array (on index 1): method(1)
The third item of the array (on index 2): main()
((and this main() method is the caller in the question.)) +2