gpt4 book ai didi

java - Java 包之间的通信

转载 作者:行者123 更新时间:2023-11-30 11:23:10 24 4
gpt4 key购买 nike

<分区>

我遇到了一个与包之间的通信有关的问题。这就是问题,是否可以在一个包中包含一个列表并将此列表导入另一个包,以便我也可以在那里使用它?

这是代码:

// this is the first package where i create the list and i've create a method to return the       list
package Pack1;
import java.util.*;

public class Lexer
{
public static LinkedList<Object> lst = new LinkedList<Object>();

public static LinkedList<Object> getList(){
return lst;
}
}

// After this, i add objects to "lst", so the list it's full of objects.
///////////////////////////////////////////////////////////////////////////////

//This is the second Package.
package Pack2;

import Pack1.*;
import java.util.*;

public class Parse {

//In the main i tried to create a List to contain the old one ("lst") but when i use the
//method getList nothing happens! So toString prints nothing.

public static void main(String[] args )
{
LinkedList<Object> list = new LinkedList<Object>();
list = Lexer.getList();
list.toString();
}

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com