简体   繁体   English

扩展链表返回问题

[英]extending linked list return issue

I'm trying to extend the LinkedList class but i'm getting a strange error, whenever i try to add an accessor class that returns a string i get the error 我正在尝试扩展LinkedList类,但是每当我尝试添加返回字符串的访问器类时,我都会遇到一个奇怪的错误,我得到了错误

found : java.lang.String required: String 找到:java.lang.String必需:字符串

I cant work out why this is happening. 我不知道为什么会这样。 (I'm pretty new to linked lists and java in general, be nice :) ) (一般来说,我对链表和Java还是很陌生的,请:))

import java.util.*;
public class MyLinkedList<String> extends LinkedList<String>
{
   private int count;     //for future use

   public void MyLinkedList()
   {
      count = 0;
   }

   public boolean add(String s)
   {
     boolean x =  super.add(s); 
     count++;
     return x;

   }


   public String toString()
   {
      return("test");
   }


}

Change your declaration to 将声明更改为

public class MyLinkedList extends LinkedList<String>

By adding <String> to your MyLinkedList class name you create a new type parameter whose name shadows the real class String . 通过添加<String>MyLinkedList类的名字,你创建一个名称阴影的真正类的新类型参数String

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

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