简体   繁体   English

如何使LinkedList从另一个类可访问main?

[英]How to make LinkedList accessible from another class to main?

How can I access the linked list to a different class that has the main method? 如何访问链表到具有main方法的其他类?

import java.util.LinkedList;

public class Project {
    public Project {
        // Linked list declaration: 
        LinkedList<Character>list = new LinkedList<Character>();
    }
}

Declare it in the original class (eg Project.java) as: 在原始类(例如Project.java)中声明为:

public static LinkedList<Character> list = new LinkedList<Character>();

Call it from another class as: 从另一个类调用它:

LinkedList<Character> ll = Project.list;

If data hiding is of essence to you, then you need to set up getters/setters for it. 如果数据隐藏对您至关重要,那么您需要为其设置getter / setter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM