Java Method.otherMethod和otherMethod之间的区别?

Java Method.otherMethod和otherMethod之间的区别?,java,list,class,linked-list,Java,List,Class,Linked List,下面是创建哈夫曼树项目中一个文件的摘录。当 “公共类hlinkdList”是由它自己初始化的,HtreNode的方法(如.next、.left、.right)的单独文件(如下所示)在hlinkdList的文件中工作没有问题。一旦“extends java.util.Abstract~”就位,HTreeNode方法就无法被引用,于是我求助于将HTreeNode复制粘贴到同一个文件中,这就是为什么第一行代码会这样显示它。将这两个文件放在同一个文件中的问题是,这会导致hlinkdList.HTreeN

下面是创建哈夫曼树项目中一个文件的摘录。当 “公共类hlinkdList”是由它自己初始化的,HtreNode的方法(如.next、.left、.right)的单独文件(如下所示)在hlinkdList的文件中工作没有问题。一旦“extends java.util.Abstract~”就位,HTreeNode方法就无法被引用,于是我求助于将HTreeNode复制粘贴到同一个文件中,这就是为什么第一行代码会这样显示它。将这两个文件放在同一个文件中的问题是,这会导致hlinkdList.HTreeNode和HTreeNode之间发生冲突(我认为),因为我保留了HTreeNode文件以防万一。这发生在一个单独的文件Huffman_编码器中,该编码器最初很好地使用了HLinkedList和HTreeNode文件(或者至少没有编译级错误),直到我决定扩展java.util.Abstract~

public class HLinkedList<HTreeNode> extends java.util.AbstractSequentialList<HTreeNode>
{

public class HTreeNode {


    public HTreeNode left;
    public HTreeNode right;
    public HTreeNode next;
    public int frequency;
    public char value;
    public String code;
    public HTreeNode(int freq, char val, HTreeNode l, HTreeNode r, HTreeNode n, String code) // code is the path taken to this node, how to explain it in code?
    {
        value = val;
        frequency = freq;
        left = l;
        right = r;
        next = n;
        code = ""; // just initialized ,but have to think through logic.
    }
}

 HTreeNode head;
static int nItem;

public HLinkedList() //constructor
{
    head = null; //inital value
    nItem = 0;//counter

}


public void insertIntoPosition(HTreeNode node, int position) //inserts into position
{
    //first, the case where it's already in the list.
        HTreeNode currNode = head;
        while(currNode.next != null)
        {
            if(currNode.value == node.value)
            {
                currNode.frequency++;
            }

            currNode = currNode.next;           
        }
        if(currNode.value == node.value)
        {
            currNode.frequency++;
        }

如果您想扩展,那么应该扩展
java.util.AbstractSequentialList
,即通用版本,而不是原始版本

您的编译器之所以抱怨,是因为您没有导入类,或者您的方法不是公共的,或者您没有以正确的方式调用它们(可能您将它们设置为非静态的,并尝试对类本身进行调用)

更新


我不确定您想要实现什么,但相信这不会产生任何编译器错误(带有一些注释)-


如果您想扩展,那么应该扩展
java.util.AbstractSequentialList
,即通用版本,而不是原始版本

您的编译器之所以抱怨,是因为您没有导入类,或者您的方法不是公共的,或者您没有以正确的方式调用它们(可能您将它们设置为非静态的,并尝试对类本身进行调用)

更新


我不确定您想要实现什么,但相信这不会产生任何编译器错误(带有一些注释)-


让我更正一下,只有1种错误类型,其中输入“Node”是必需的,但找到了输入“List.Node”。我现在很确定这是因为它们都在同一个文件中,并且可能可以调整我的代码,以便我需要List.Node(因为我不确定如何消除潜在问题)奇怪的是,将预期输入更改为HLinkedList.HTreeNode无效,现在在需要输入类型“List.Node”的地方出现错误(我以为我输入了这样的类型)但是找到了“Node”类型让我更正一下,只有一种错误类型,输入“Node”是必需的,但是输入“List.Node”是可以找到的。我现在很确定这是因为它们都在同一个文件中,并且可能可以调整我的代码,所以我需要List.Node(因为我不知道如何摆脱潜在的问题)奇怪的是,将预期的输入更改为hlinkdList.HTreeNode不起作用,现在在需要输入类型“List.Node”的地方出现了错误(我以为我输入了这种类型),但找到了“Node”类型问题是,我在自制的节点中有一堆参数(如频率和代码值)如果我扩展了它,并且没有在同一个文件中声明我的节点,这一切都会变红。也就是说,如果我没有扩展,我可以在一个单独的类和单独的文件中声明我的节点类型,但是一旦我扩展了它,我必须将我的节点类型声明放到同一个文件中,这会把我在项目的其他部分的东西搞砸你应该在这里发布相关代码,这样我们就知道你在做什么。编辑过的帖子。不确定为什么扩展它会在节点级产生问题,除非扩展的东西被明确定义到节点级?@Sukwoo:除非它解决了你的问题,否则你不应该接受答案。你应该撤销它,让其他人来检查问题是,我在自制的节点中有很多参数(比如频率和代码值)如果我扩展了它,并且没有在同一个文件中声明我的节点,这一切都会变红。也就是说,如果我没有扩展,我可以在一个单独的类和单独的文件中声明我的节点类型,但是一旦我扩展了它,我必须将我的节点类型声明放到同一个文件中,这会把我在项目的其他部分的东西搞砸你应该在这里发布相关代码,这样我们就知道你在做什么。编辑过的帖子。不确定为什么扩展它会在节点级产生问题,除非扩展的东西被明确定义到节点级?@Sukwoo:除非它解决了你的问题,否则你不应该接受答案。你应该撤销它,让其他人来检查回答你的问题。
public class HTreeNode {


    public static  HTreeNode left;
    public HTreeNode right;
    public HTreeNode next;
    public int frequency;
    public char value;
    public String code;
    public HTreeNode(int freq, char val, HTreeNode l, HTreeNode r, HTreeNode n, String code) // code is the path taken to this node, how to explain it in code?
    {
        value = val;
        frequency = freq;
        left = l;
        right = r;
        next = n;
        code = ""; // just initialized ,but have to think through logic.
    }
}
//E is a type parameter, meaning HLinkedList<E> is generic
public class HLinkedList<E> extends java.util.AbstractSequentialList<E> {

    //I think you can keep this private here, this only helps you to implement your
    //version of AbstractSequentialList, for anyone who will be using HLinkedList
    //are not going to worry about it
    private static class HTreeNode {
        public HTreeNode left;
        public HTreeNode right;
        public HTreeNode next;
        public int frequency;
        public char value;
        public String code;

        public HTreeNode(int freq, char val, HTreeNode l, HTreeNode r, HTreeNode n, String code)  {
            value = val;
            frequency = freq;
            left = l;
            right = r;
            next = n;
            code = ""; 
        }
    }

    private HTreeNode head;
    private int nItem; //made this non-static, each instance will need it's own copy

    public HLinkedList()  {
        this.head = null;
        this.nItem = 0;
    }

    public void insertIntoPosition(E element, int position)  {
        // probably create a new node here for element
        // and fix it at the location specified
    }

    //This is an abstract method declared in AbstractSequentialList
    //You need provide an implementation of it
    @Override
    public ListIterator<E> listIterator(int index) {

        return null;
    }

    //This is an abstract method declared in AbstractSequentialList
    //You need provide an implementation of it    
    @Override
    public int size() {

        return 0;
    }
}
HLinkedList<Integer> list = new HLinkedList<Integer>();
//or
HLinkedList<String> list = new HLinkedList<String>();