Hier eine Antwort für die Menschen hier landen und sind intersted in.
die Klasse erstellen
import java.util.concurrent.Callable;
public class Clazz {
public static void main(String[] args) throws Exception {
new Clazz().method();
}
public void method() throws Exception {
Clazz.staticMethod(() -> {
Integer x = 1;
Long y = 2L;
y = x * y; // I need a Break point here
return y;
});
}
private static void staticMethod(Callable i) throws Exception {
System.out.println("i = " + i.call());
}
}
kompilieren
javac Clazz.java
Start jdb für diese Klasse
jdb Clazz
Initializing jdb ...
einen Haltepunkt in der Hauptmethode gesetzt stop
> stop in Clazz.main
Deferring breakpoint Clazz.main.
It will be set after the class is loaded.
die Debug-Sitzung beginnen mit run
> run
run Clazz
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint Clazz.main
Breakpoint hit: "thread=main", Clazz.main(), line=6 bci=0
6 new Clazz().method();
Jetzt wird der Debugger in der Hauptmethode kurz vor dem Aufruf new Clazz().method();
gestoppt.
Um die Linie, die wir finden Interesse an uns die Quelle
main[1] list
2
3 public class Clazz {
4
5 public static void main(String[] args) throws Exception {
6 => new Clazz().method();
7 }
8
9 public void method() throws Exception {
10 Clazz.staticMethod(() -> {
11 Integer x = 1;
main[1] list 12
8
9 public void method() throws Exception {
10 Clazz.staticMethod(() -> {
11 Integer x = 1;
12 => Long y = 2L;
13 y = x * y; // I need a Break point here
14 return y;
15 });
16 }
17
Der Befehl list 12
benötigt wird, um zur Liste der folgenden Zeilen list
. In der Ausgabe können wir sehen, dass wir bei Zeile 13
stoppen möchten. Werfen wir also einen neuen Haltepunkt setzen dort mit dem stop
Befehl
main[1] stop at Clazz:13
Set breakpoint Clazz:13
die Ausführung bis zum nächsten Haltepunkt Problem weiterhin den Befehl cont
main[1] cont
>
Breakpoint hit: "thread=main", Clazz.lambda$method$0(), line=13 bci=12
13 y = x * y; // I need a Break point here
sind wir nicht auf der Linie 13
und könnte zum Beispiel die Werte von dump
x
und y
.
main[1] dump x
x = {
MIN_VALUE: -2147483648
MAX_VALUE: 2147483647
TYPE: instance of java.lang.Class(reflected class=int, id=568)
digits: instance of char[36] (id=569)
DigitTens: instance of char[100] (id=570)
DigitOnes: instance of char[100] (id=571)
sizeTable: instance of int[10] (id=572)
value: 1
SIZE: 32
BYTES: 4
serialVersionUID: 1360826667806852920
java.lang.Number.serialVersionUID: -8742448824652078965
}
main[1] dump y
y = {
MIN_VALUE: -9223372036854775808
MAX_VALUE: 9223372036854775807
TYPE: instance of java.lang.Class(reflected class=long, id=574)
value: 2
SIZE: 64
BYTES: 8
serialVersionUID: 4290774380558885855
java.lang.Number.serialVersionUID: -8742448824652078965
}
going ein step
weiter
main[1] step
>
Step completed: "thread=main", Clazz.lambda$method$0(), line=14 bci=26
14
konnten wir jetzt dump
wieder der Wert von y
main[1] dump y
y = {
MIN_VALUE: -9223372036854775808
MAX_VALUE: 9223372036854775807
TYPE: instance of java.lang.Class(reflected class=long, id=574)
value: 2
SIZE: 64
BYTES: 8
serialVersionUID: 4290774380558885855
java.lang.Number.serialVersionUID: -8742448824652078965
}
Kennen Sie die Zeilennummer? Sie könnten versuchen, "Stop bei MyClass: 22", wo 22 ist die Zeilennummer und MyClass ist die Sache, die die Methode und ihre Lambda-Ausdruck enthält. –
ja ich das war die Art, wie ich es versuchte, aber immer noch ignoriert mich, ich denke jetzt, dass dies ist wahrscheinlich ein Problem mit der 'staticMethod' oder mit dem Lambda darauf – carpinchosaurio
Welcher Typ wird von' Clazz.staticMethod (..) '? – SubOptimal