Java a :
TraintListFrom Tailtohead 유형의 인스턴스 인스턴스에 액세스 할 수 없습니다. 인스턴스 인스턴스와 함께 할당 자격을 갖추어야합니다
type of printlistlistfrom tailtohead (egxnew a () 여기서 x는 printlistfrom tailtohead의 인스턴스)입니다.
源代码为 :
public class printlistfrom tailtohead {public static void main (string [] args) {listnode one = new ListNode (1); ListNode Two = new ListNode (2); ListNode Three = new ListNode (3); one.next = 2; 2.next = Three; arrayList <integer> result = printListFrom Head (system. + 결과);} class listnode {public int val; public listnode next; public listnode () {} public listnode (int val) {this.val = val;}} public static arraylist <integer> printlistfrompteftohead (listnode) {listnode) {listnode) <new Stack <intnode> (); {stack.push (listnode.val); listnode = listnode.next;} arraylist <integer> arraylist = new arraylist <integer> (); while (! stack.isempty ()) {arraylist.add (stack.pop ()); retraylist;}}}问题解释 :
代码中, 我的 ListNode 类是定义在 printlistlistlistlistlistlistlistlistlistlistnode 类中的内部类。 listnode 内部类是动态的内部类, 而我的 main 方法是 정적 静态的。
就好比静态的方法不能调用动态的方法一样。
有两种解决办法 :
第一种 :
将内部类 목록 노드 ode 정적 的类。
第二种 :
将内部类 ListNode ode printlistfrom tailtohead 类外边定义。
两种解决方法 :
第一种 :
public class printlistfrom tailtohead {public static void main (string [] args) {listnode one = new ListNode (1); ListNode Two = new ListNode (2); ListNode Three = new ListNode (3); one.next = 2; 2.next = Three; arrayList <integer> result = printListFrom Head (system. + 결과);} 정적 클래스리스트 노드 {public int val; public listnode next; public listnode () {} public listnode (int val) {this.val = val;}}第二种 :
public class printlistfrom tailtohead {public static void main (string [] args) {listnode one = new listnode (1); ListNode Two = new ListNode (2); ListNode Three = new ListNode (3); one.next = 2; public static arraylist <Integer> printlisttohead (listnode listnode) (listnode) {stack <integer> stack = new stack <integer> (); while (listnode! = null) {stack.push (listnode.val); listnode = listnode.next;} arraylist = new arraylist <integer> (); while (! stack.isempty () {arrayList.Add (stack.pop ());} return arrayList;}} 클래스리스트 노드 {public int val; public listNode next; public listNode () {} public listNode (int val) {this.val = val;}}以上所述是小编给大家介绍的 Java a ttailtohead 유형의 인스턴스 인스턴스에 액세스 할 수 있습니다.